home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / Emulation_Include_Files / wincrypt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  313.3 KB  |  7,889 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (c) 1992-1998. Microsoft Corporation.  All Rights Reserved.
  5. //
  6. //  File:       wincrypt.h
  7. //
  8. //  Contents:   Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11.  
  12. #ifndef __WINCRYPT_H__
  13. #define __WINCRYPT_H__
  14.  
  15.  
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19.  
  20. #ifndef _HRESULT_DEFINED
  21. #define _HRESULT_DEFINED
  22. typedef LONG HRESULT;
  23.  
  24. #endif // !_HRESULT_DEFINED
  25.  
  26. #if !defined(_CRYPT32_)
  27. #define WINCRYPT32API DECLSPEC_IMPORT
  28. #else
  29. #define WINCRYPT32API
  30. #endif
  31.  
  32. //
  33. // Algorithm IDs and Flags
  34. //
  35.  
  36. // ALG_ID crackers
  37. #define GET_ALG_CLASS(x)                (x & (7 << 13))
  38. #define GET_ALG_TYPE(x)                 (x & (15 << 9))
  39. #define GET_ALG_SID(x)                  (x & (511))
  40.  
  41. // Algorithm classes
  42. #define ALG_CLASS_ANY                   (0)
  43. #define ALG_CLASS_SIGNATURE             (1 << 13)
  44. #define ALG_CLASS_MSG_ENCRYPT           (2 << 13)
  45. #define ALG_CLASS_DATA_ENCRYPT          (3 << 13)
  46. #define ALG_CLASS_HASH                  (4 << 13)
  47. #define ALG_CLASS_KEY_EXCHANGE          (5 << 13)
  48.  
  49. // Algorithm types
  50. #define ALG_TYPE_ANY                    (0)
  51. #define ALG_TYPE_DSS                    (1 << 9)
  52. #define ALG_TYPE_RSA                    (2 << 9)
  53. #define ALG_TYPE_BLOCK                  (3 << 9)
  54. #define ALG_TYPE_STREAM                 (4 << 9)
  55. #define ALG_TYPE_DH                     (5 << 9)
  56. #define ALG_TYPE_SECURECHANNEL          (6 << 9)
  57.  
  58. // Generic sub-ids
  59. #define ALG_SID_ANY                     (0)
  60.  
  61. // Some RSA sub-ids
  62. #define ALG_SID_RSA_ANY                 0
  63. #define ALG_SID_RSA_PKCS                1
  64. #define ALG_SID_RSA_MSATWORK            2
  65. #define ALG_SID_RSA_ENTRUST             3
  66. #define ALG_SID_RSA_PGP                 4
  67.  
  68. // Some DSS sub-ids
  69. //
  70. #define ALG_SID_DSS_ANY                 0
  71. #define ALG_SID_DSS_PKCS                1
  72. #define ALG_SID_DSS_DMS                 2
  73.  
  74. // Block cipher sub ids
  75. // DES sub_ids
  76. #define ALG_SID_DES                     1
  77. #define ALG_SID_3DES                    3
  78. #define ALG_SID_DESX                    4
  79. #define ALG_SID_IDEA                    5
  80. #define ALG_SID_CAST                    6
  81. #define ALG_SID_SAFERSK64               7
  82. #define ALG_SID_SAFERSK128              8
  83. #define ALG_SID_3DES_112                9
  84. #define ALG_SID_CYLINK_MEK              12
  85. #define ALG_SID_RC5                     13
  86.  
  87. // Fortezza sub-ids
  88. #define ALG_SID_SKIPJACK                10
  89. #define ALG_SID_TEK                     11
  90.  
  91. // KP_MODE
  92. #define CRYPT_MODE_CBCI                 6       // ANSI CBC Interleaved
  93. #define CRYPT_MODE_CFBP                 7       // ANSI CFB Pipelined
  94. #define CRYPT_MODE_OFBP                 8       // ANSI OFB Pipelined
  95. #define CRYPT_MODE_CBCOFM               9       // ANSI CBC + OF Masking
  96. #define CRYPT_MODE_CBCOFMI              10      // ANSI CBC + OFM Interleaved
  97.  
  98. // RC2 sub-ids
  99. #define ALG_SID_RC2                     2
  100.  
  101. // Stream cipher sub-ids
  102. #define ALG_SID_RC4                     1
  103. #define ALG_SID_SEAL                    2
  104.  
  105. // Diffie-Hellman sub-ids
  106. #define ALG_SID_DH_SANDF                1
  107. #define ALG_SID_DH_EPHEM                2
  108. #define ALG_SID_AGREED_KEY_ANY          3
  109. #define ALG_SID_KEA                     4
  110.  
  111. // Hash sub ids
  112. #define ALG_SID_MD2                     1
  113. #define ALG_SID_MD4                     2
  114. #define ALG_SID_MD5                     3
  115. #define ALG_SID_SHA                     4
  116. #define ALG_SID_SHA1                    4
  117. #define ALG_SID_MAC                     5
  118. #define ALG_SID_RIPEMD                  6
  119. #define ALG_SID_RIPEMD160               7
  120. #define ALG_SID_SSL3SHAMD5              8
  121. #define ALG_SID_HMAC                    9
  122.  
  123. // secure channel sub ids
  124. #define ALG_SID_SSL3_MASTER             1
  125. #define ALG_SID_SCHANNEL_MASTER_HASH    2
  126. #define ALG_SID_SCHANNEL_MAC_KEY        3
  127. #define ALG_SID_PCT1_MASTER             4
  128. #define ALG_SID_SSL2_MASTER             5
  129. #define ALG_SID_TLS1_MASTER             6
  130. #define ALG_SID_SCHANNEL_ENC_KEY        7
  131.  
  132. // Our silly example sub-id
  133. #define ALG_SID_EXAMPLE                 80
  134.  
  135. #ifndef ALGIDDEF
  136. #define ALGIDDEF
  137. typedef unsigned int ALG_ID;
  138. #endif
  139.  
  140. // algorithm identifier definitions
  141. #define CALG_MD2                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  142. #define CALG_MD4                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  143. #define CALG_MD5                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  144. #define CALG_SHA                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  145. #define CALG_SHA1                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA1)
  146. #define CALG_MAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  147. #define CALG_RSA_SIGN            (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  148. #define CALG_DSS_SIGN            (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  149. #define CALG_RSA_KEYX            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  150. #define CALG_DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  151. #define CALG_3DES_112            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES_112)
  152. #define CALG_3DES                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_3DES)
  153. #define CALG_RC2                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  154. #define CALG_RC4                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  155. #define CALG_SEAL                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  156. #define CALG_DH_SF              (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_SANDF)
  157. #define CALG_DH_EPHEM            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_DH_EPHEM)
  158. #define CALG_AGREEDKEY_ANY        (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_AGREED_KEY_ANY)
  159. #define CALG_KEA_KEYX            (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_DH|ALG_SID_KEA)
  160. #define CALG_HUGHES_MD5         (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_ANY|ALG_SID_MD5)
  161. #define CALG_SKIPJACK            (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_SKIPJACK)
  162. #define CALG_TEK                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_TEK)
  163. #define CALG_CYLINK_MEK         (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_CYLINK_MEK)
  164. #define CALG_SSL3_SHAMD5        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
  165. #define CALG_SSL3_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL3_MASTER)
  166. #define CALG_SCHANNEL_MASTER_HASH   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MASTER_HASH)
  167. #define CALG_SCHANNEL_MAC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_MAC_KEY)
  168. #define CALG_SCHANNEL_ENC_KEY   (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SCHANNEL_ENC_KEY)
  169. #define CALG_PCT1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_PCT1_MASTER)
  170. #define CALG_SSL2_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_SSL2_MASTER)
  171. #define CALG_TLS1_MASTER        (ALG_CLASS_MSG_ENCRYPT|ALG_TYPE_SECURECHANNEL|ALG_SID_TLS1_MASTER)
  172. #define CALG_RC5                (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC5)
  173. #define CALG_HMAC                (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_HMAC)
  174.  
  175. typedef struct _VTableProvStruc {
  176.     DWORD   Version;
  177.     FARPROC FuncVerifyImage;
  178.     FARPROC FuncReturnhWnd;
  179.     DWORD   dwProvType;
  180.     BYTE    *pbContextInfo;
  181.     DWORD    cbContextInfo;
  182. } VTableProvStruc, *PVTableProvStruc;
  183.  
  184. typedef unsigned long HCRYPTPROV;
  185. typedef unsigned long HCRYPTKEY;
  186. typedef unsigned long HCRYPTHASH;
  187.  
  188. // dwFlags definitions for CryptAcquireContext
  189. #define CRYPT_VERIFYCONTEXT     0xF0000000
  190. #define CRYPT_NEWKEYSET         0x00000008
  191. #define CRYPT_DELETEKEYSET      0x00000010
  192. #define CRYPT_MACHINE_KEYSET    0x00000020
  193.  
  194. // dwFlag definitions for CryptGenKey
  195. #define CRYPT_EXPORTABLE        0x00000001
  196. #define CRYPT_USER_PROTECTED    0x00000002
  197. #define CRYPT_CREATE_SALT       0x00000004
  198. #define CRYPT_UPDATE_KEY        0x00000008
  199. #define CRYPT_NO_SALT           0x00000010
  200. #define CRYPT_PREGEN            0x00000040
  201. #define CRYPT_RECIPIENT         0x00000010
  202. #define CRYPT_INITIATOR         0x00000040
  203. #define CRYPT_ONLINE            0x00000080
  204. #define CRYPT_SF                0x00000100
  205. #define CRYPT_CREATE_IV         0x00000200
  206. #define CRYPT_KEK               0x00000400
  207. #define CRYPT_DATA_KEY          0x00000800
  208.  
  209. // dwFlags definitions for CryptDeriveKey
  210. #define    CRYPT_SERVER            0x00000400
  211.  
  212. #define KEY_LENGTH_MASK         0xFFFF0000
  213.  
  214. // dwFlag definitions for CryptExportKey
  215. #define CRYPT_Y_ONLY            0x00000001
  216. #define CRYPT_SSL2_SLUMMING     0x00000002
  217.  
  218. // dwFlags definitions for CryptHashSessionKey
  219. #define    CRYPT_LITTLE_ENDIAN        0x00000001
  220.  
  221. // dwFlag definitions for CryptSetProviderEx and CryptGetDefaultProvider
  222. #define CRYPT_MACHINE_DEFAULT   0x00000001
  223. #define CRYPT_USER_DEFAULT      0x00000002
  224. #define CRYPT_DELETE_DEFAULT    0x00000004
  225.  
  226. // exported key blob definitions
  227. #define SIMPLEBLOB              0x1
  228. #define PUBLICKEYBLOB           0x6
  229. #define PRIVATEKEYBLOB          0x7
  230. #define PLAINTEXTKEYBLOB        0x8
  231.  
  232. #define AT_KEYEXCHANGE          1
  233. #define AT_SIGNATURE            2
  234.  
  235. #define CRYPT_USERDATA          1
  236.  
  237. // dwParam
  238. #define KP_IV                   1       // Initialization vector
  239. #define KP_SALT                 2       // Salt value
  240. #define KP_PADDING              3       // Padding values
  241. #define KP_MODE                 4       // Mode of the cipher
  242. #define KP_MODE_BITS            5       // Number of bits to feedback
  243. #define KP_PERMISSIONS          6       // Key permissions DWORD
  244. #define KP_ALGID                7       // Key algorithm
  245. #define KP_BLOCKLEN             8       // Block size of the cipher
  246. #define KP_KEYLEN               9       // Length of key in bits
  247. #define KP_SALT_EX              10      // Length of salt in bytes
  248. #define KP_P                    11      // DSS/Diffie-Hellman P value
  249. #define KP_G                    12      // DSS/Diffie-Hellman G value
  250. #define KP_Q                    13      // DSS Q value
  251. #define KP_X                    14      // Diffie-Hellman X value
  252. #define KP_Y                    15      // Y value
  253. #define KP_RA                   16      // Fortezza RA value
  254. #define KP_RB                   17      // Fortezza RB value
  255. #define KP_INFO                 18      // for putting information into an RSA envelope
  256. #define KP_EFFECTIVE_KEYLEN     19      // setting and getting RC2 effective key length
  257. #define KP_SCHANNEL_ALG            20      // for setting the Secure Channel algorithms
  258. #define KP_CLIENT_RANDOM        21      // for setting the Secure Channel client random data
  259. #define KP_SERVER_RANDOM        22      // for setting the Secure Channel server random data
  260. #define    KP_RP                    23
  261. #define    KP_PRECOMP_MD5            24
  262. #define    KP_PRECOMP_SHA            25
  263. #define KP_CERTIFICATE          26      // for setting Secure Channel certificate data (PCT1)
  264. #define KP_CLEAR_KEY            27      // for setting Secure Channel clear key data (PCT1)
  265. #define KP_PUB_EX_LEN           28
  266. #define KP_PUB_EX_VAL           29
  267.  
  268. // KP_PADDING
  269. #define PKCS5_PADDING           1       // PKCS 5 (sec 6.2) padding method
  270. #define RANDOM_PADDING            2
  271. #define    ZERO_PADDING            3
  272.  
  273. // KP_MODE
  274. #define CRYPT_MODE_CBC          1       // Cipher block chaining
  275. #define CRYPT_MODE_ECB          2       // Electronic code book
  276. #define CRYPT_MODE_OFB          3       // Output feedback mode
  277. #define CRYPT_MODE_CFB          4       // Cipher feedback mode
  278. #define CRYPT_MODE_CTS          5       // Ciphertext stealing mode
  279.  
  280. // KP_PERMISSIONS
  281. #define CRYPT_ENCRYPT           0x0001  // Allow encryption
  282. #define CRYPT_DECRYPT           0x0002  // Allow decryption
  283. #define CRYPT_EXPORT            0x0004  // Allow key to be exported
  284. #define CRYPT_READ              0x0008  // Allow parameters to be read
  285. #define CRYPT_WRITE             0x0010  // Allow parameters to be set
  286. #define CRYPT_MAC               0x0020  // Allow MACs to be used with key
  287. #define CRYPT_EXPORT_KEY        0x0040  // Allow key to be used for exporting keys
  288. #define CRYPT_IMPORT_KEY        0x0080  // Allow key to be used for importing keys
  289.  
  290. #define HP_ALGID                0x0001  // Hash algorithm
  291. #define HP_HASHVAL              0x0002  // Hash value
  292. #define HP_HASHSIZE             0x0004  // Hash value size
  293. #define HP_HMAC_INFO            0x0005  // information for creating an HMAC
  294.  
  295. #define CRYPT_FAILED            FALSE
  296. #define CRYPT_SUCCEED           TRUE
  297.  
  298. #define RCRYPT_SUCCEEDED(rt)     ((rt) == CRYPT_SUCCEED)
  299. #define RCRYPT_FAILED(rt)        ((rt) == CRYPT_FAILED)
  300.  
  301. //
  302. // CryptGetProvParam
  303. //
  304. #define PP_ENUMALGS             1
  305. #define PP_ENUMCONTAINERS       2
  306. #define PP_IMPTYPE              3
  307. #define PP_NAME                 4
  308. #define PP_VERSION              5
  309. #define PP_CONTAINER            6
  310. #define PP_CHANGE_PASSWORD      7
  311. #define PP_KEYSET_SEC_DESCR     8       // get/set security descriptor of keyset
  312. #define PP_CERTCHAIN            9       // for retrieving certificates from tokens
  313. #define PP_KEY_TYPE_SUBTYPE     10
  314. #define PP_PROVTYPE             16
  315. #define PP_KEYSTORAGE           17
  316. #define PP_APPLI_CERT           18
  317. #define PP_SYM_KEYSIZE          19
  318. #define PP_SESSION_KEYSIZE      20
  319. #define PP_UI_PROMPT            21
  320. #define PP_ENUMALGS_EX          22
  321.  
  322. #define CRYPT_FIRST             1
  323. #define CRYPT_NEXT              2
  324.  
  325. #define CRYPT_IMPL_HARDWARE     1
  326. #define CRYPT_IMPL_SOFTWARE     2
  327. #define CRYPT_IMPL_MIXED        3
  328. #define CRYPT_IMPL_UNKNOWN      4
  329.  
  330. // key storage flags
  331. #define CRYPT_SEC_DESCR         0x00000001
  332. #define CRYPT_PSTORE            0x00000002
  333. #define CRYPT_UI_PROMPT         0x00000004
  334.  
  335. // protocol flags
  336. #define CRYPT_FLAG_PCT1         0x0001
  337. #define CRYPT_FLAG_SSL2         0x0002
  338. #define CRYPT_FLAG_SSL3         0x0004
  339. #define CRYPT_FLAG_TLS1         0x0008
  340.  
  341. //
  342. // CryptSetProvParam
  343. //
  344. #define PP_CLIENT_HWND          1
  345. #define PP_CONTEXT_INFO            11
  346. #define    PP_KEYEXCHANGE_KEYSIZE    12
  347. #define    PP_SIGNATURE_KEYSIZE    13
  348. #define PP_KEYEXCHANGE_ALG      14
  349. #define PP_SIGNATURE_ALG        15
  350. #define PP_DELETEKEY            24
  351.  
  352. #define PROV_RSA_FULL           1
  353. #define PROV_RSA_SIG            2
  354. #define PROV_DSS                3
  355. #define PROV_FORTEZZA           4
  356. #define PROV_MS_EXCHANGE        5
  357. #define PROV_SSL                6
  358. #define PROV_RSA_SCHANNEL       12
  359. #define PROV_DSS_DH             13
  360. #define PROV_EC_ECDSA_SIG       14
  361. #define PROV_EC_ECNRA_SIG       15
  362. #define PROV_EC_ECDSA_FULL      16
  363. #define PROV_EC_ECNRA_FULL      17
  364. #define PROV_SPYRUS_LYNKS       20
  365.  
  366. //
  367. // STT defined Providers
  368. //
  369. #define PROV_STT_MER                    7
  370. #define PROV_STT_ACQ                    8
  371. #define PROV_STT_BRND                   9
  372. #define PROV_STT_ROOT                   10
  373. #define PROV_STT_ISS                    11
  374.  
  375. //
  376. // Provider friendly names
  377. //
  378. #define MS_DEF_PROV_A       "Microsoft Base Cryptographic Provider v1.0"
  379. #define MS_DEF_PROV_W       L"Microsoft Base Cryptographic Provider v1.0"
  380. #ifdef UNICODE
  381. #define MS_DEF_PROV         MS_DEF_PROV_W
  382. #else
  383. #define MS_DEF_PROV         MS_DEF_PROV_A
  384. #endif
  385.  
  386. #define MS_ENHANCED_PROV_A       "Microsoft Enhanced Cryptographic Provider v1.0"
  387. #define MS_ENHANCED_PROV_W       L"Microsoft Enhanced Cryptographic Provider v1.0"
  388. #ifdef UNICODE
  389. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_W
  390. #else
  391. #define MS_ENHANCED_PROV         MS_ENHANCED_PROV_A
  392. #endif
  393.  
  394. #define MS_DEF_RSA_SIG_PROV_A    "Microsoft RSA Signature Cryptographic Provider"
  395. #define MS_DEF_RSA_SIG_PROV_W    L"Microsoft RSA Signature Cryptographic Provider"
  396. #ifdef UNICODE
  397. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_W
  398. #else
  399. #define MS_DEF_RSA_SIG_PROV      MS_DEF_RSA_SIG_PROV_A
  400. #endif
  401.  
  402. #define MS_DEF_RSA_SCHANNEL_PROV_A  "Microsoft Base RSA SChannel Cryptographic Provider"
  403. #define MS_DEF_RSA_SCHANNEL_PROV_W  L"Microsoft Base RSA SChannel Cryptographic Provider"
  404. #ifdef UNICODE
  405. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_W
  406. #else
  407. #define MS_DEF_RSA_SCHANNEL_PROV         MS_DEF_RSA_SCHANNEL_PROV_A
  408. #endif
  409.  
  410. #define MS_ENHANCED_RSA_SCHANNEL_PROV_A  "Microsoft Enhanced RSA SChannel Cryptographic Provider"
  411. #define MS_ENHANCED_RSA_SCHANNEL_PROV_W  L"Microsoft Enhanced RSA SChannel Cryptographic Provider"
  412. #ifdef UNICODE
  413. #define MS_ENHANCED_RSA_SCHANNEL_PROV    MS_ENHANCED_RSA_SCHANNEL_PROV_W
  414. #else
  415. #define MS_ENHANCED_RSA_SCHANNEL_PROV    MS_ENHANCED_RSA_SCHANNEL_PROV_A
  416. #endif
  417.  
  418. #define MS_DEF_DSS_PROV_A        "Microsoft Base DSS Cryptographic Provider"
  419. #define MS_DEF_DSS_PROV_W        L"Microsoft Base DSS Cryptographic Provider"
  420. #ifdef UNICODE
  421. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_W
  422. #else
  423. #define MS_DEF_DSS_PROV          MS_DEF_DSS_PROV_A
  424. #endif
  425.  
  426. #define MS_DEF_DSS_DH_PROV_A    "Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  427. #define MS_DEF_DSS_DH_PROV_W    L"Microsoft Base DSS and Diffie-Hellman Cryptographic Provider"
  428. #ifdef UNICODE
  429. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_W
  430. #else
  431. #define MS_DEF_DSS_DH_PROV      MS_DEF_DSS_DH_PROV_A
  432. #endif
  433.  
  434.  
  435. #define MAXUIDLEN               64
  436.  
  437. #define CUR_BLOB_VERSION        2
  438.  
  439. // structure for use with CryptSetHashParam with CALG_HMAC
  440. typedef struct _HMAC_Info {
  441.         ALG_ID  HashAlgid;
  442.         BYTE    *pbInnerString;
  443.         DWORD   cbInnerString;
  444.         BYTE    *pbOuterString;
  445.         DWORD   cbOuterString;
  446. } HMAC_INFO, *PHMAC_INFO;
  447.  
  448. // structure for use with CryptSetKeyParam with KP_SCHANNEL_ALG
  449. typedef struct _SCHANNEL_ALG {
  450.         DWORD   dwUse;
  451.         ALG_ID  Algid;
  452.         DWORD   cBits;
  453. } SCHANNEL_ALG, *PSCHANNEL_ALG;
  454.  
  455. // uses of algortihms for SCHANNEL_ALG structure
  456. #define     SCHANNEL_MAC_KEY    0x00000000
  457. #define     SCHANNEL_ENC_KEY    0x00000001
  458.  
  459. typedef struct _PROV_ENUMALGS {
  460.     ALG_ID    aiAlgid;
  461.     DWORD     dwBitLen;
  462.     DWORD     dwNameLen;
  463.     CHAR      szName[20];
  464. } PROV_ENUMALGS;
  465.  
  466. typedef struct _PROV_ENUMALGS_EX {
  467.     ALG_ID    aiAlgid;
  468.     DWORD     dwDefaultLen;
  469.     DWORD     dwMinLen;
  470.     DWORD     dwMaxLen;
  471.     DWORD     dwProtocols;
  472.     DWORD     dwNameLen;
  473.     CHAR      szName[20];
  474.     DWORD     dwLongNameLen;
  475.     CHAR      szLongName[40];
  476. } PROV_ENUMALGS_EX;
  477.  
  478. typedef struct _PUBLICKEYSTRUC {
  479.         BYTE    bType;
  480.         BYTE    bVersion;
  481.         WORD    reserved;
  482.         ALG_ID  aiKeyAlg;
  483. } BLOBHEADER, PUBLICKEYSTRUC;
  484.  
  485. typedef struct _RSAPUBKEY {
  486.         DWORD   magic;                  // Has to be RSA1
  487.         DWORD   bitlen;                 // # of bits in modulus
  488.         DWORD   pubexp;                 // public exponent
  489.                                         // Modulus data follows
  490. } RSAPUBKEY;
  491.  
  492. typedef struct _PUBKEY {
  493.         DWORD   magic;
  494.         DWORD   bitlen;                 // # of bits in modulus
  495. } DHPUBKEY, DSSPUBKEY, KEAPUBKEY, TEKPUBKEY;
  496.  
  497. typedef struct _DSSSEED {
  498.         DWORD   counter;
  499.         BYTE    seed[20];
  500. } DSSSEED;
  501.  
  502. typedef struct _KEY_TYPE_SUBTYPE {
  503.         DWORD   dwKeySpec;
  504.         GUID    Type;
  505.         GUID    Subtype;
  506. } KEY_TYPE_SUBTYPE, *PKEY_TYPE_SUBTYPE;
  507.  
  508.  
  509. WINADVAPI
  510. BOOL
  511. WINAPI
  512. CryptAcquireContextA(
  513.     HCRYPTPROV *phProv,
  514.     LPCSTR pszContainer,
  515.     LPCSTR pszProvider,
  516.     DWORD dwProvType,
  517.     DWORD dwFlags);
  518. WINADVAPI
  519. BOOL
  520. WINAPI
  521. CryptAcquireContextW(
  522.     HCRYPTPROV *phProv,
  523.     LPCWSTR pszContainer,
  524.     LPCWSTR pszProvider,
  525.     DWORD dwProvType,
  526.     DWORD dwFlags);
  527. #ifdef UNICODE
  528. #define CryptAcquireContext  CryptAcquireContextW
  529. #else
  530. #define CryptAcquireContext  CryptAcquireContextA
  531. #endif // !UNICODE
  532.  
  533.  
  534. WINADVAPI
  535. BOOL
  536. WINAPI
  537. CryptReleaseContext(
  538.     HCRYPTPROV hProv,
  539.     DWORD dwFlags);
  540.  
  541.  
  542. WINADVAPI
  543. BOOL
  544. WINAPI
  545. CryptGenKey(
  546.     HCRYPTPROV hProv,
  547.     ALG_ID Algid,
  548.     DWORD dwFlags,
  549.     HCRYPTKEY *phKey);
  550.  
  551. WINADVAPI
  552. BOOL
  553. WINAPI
  554. CryptDeriveKey(
  555.     HCRYPTPROV hProv,
  556.     ALG_ID Algid,
  557.     HCRYPTHASH hBaseData,
  558.     DWORD dwFlags,
  559.     HCRYPTKEY *phKey);
  560.  
  561.  
  562. WINADVAPI
  563. BOOL
  564. WINAPI
  565. CryptDestroyKey(
  566.     HCRYPTKEY hKey);
  567.  
  568. WINADVAPI
  569. BOOL
  570. WINAPI
  571. CryptSetKeyParam(
  572.     HCRYPTKEY hKey,
  573.     DWORD dwParam,
  574.     BYTE *pbData,
  575.     DWORD dwFlags);
  576.  
  577. WINADVAPI
  578. BOOL
  579. WINAPI
  580. CryptGetKeyParam(
  581.     HCRYPTKEY hKey,
  582.     DWORD dwParam,
  583.     BYTE *pbData,
  584.     DWORD *pdwDataLen,
  585.     DWORD dwFlags);
  586.  
  587. WINADVAPI
  588. BOOL
  589. WINAPI
  590. CryptSetHashParam(
  591.     HCRYPTHASH hHash,
  592.     DWORD dwParam,
  593.     BYTE *pbData,
  594.     DWORD dwFlags);
  595.  
  596. WINADVAPI
  597. BOOL
  598. WINAPI
  599. CryptGetHashParam(
  600.     HCRYPTHASH hHash,
  601.     DWORD dwParam,
  602.     BYTE *pbData,
  603.     DWORD *pdwDataLen,
  604.     DWORD dwFlags);
  605.  
  606. WINADVAPI
  607. BOOL
  608. WINAPI
  609. CryptSetProvParam(
  610.     HCRYPTPROV hProv,
  611.     DWORD dwParam,
  612.     BYTE *pbData,
  613.     DWORD dwFlags);
  614.  
  615. WINADVAPI
  616. BOOL
  617. WINAPI
  618. CryptGetProvParam(
  619.     HCRYPTPROV hProv,
  620.     DWORD dwParam,
  621.     BYTE *pbData,
  622.     DWORD *pdwDataLen,
  623.     DWORD dwFlags);
  624.  
  625. WINADVAPI
  626. BOOL
  627. WINAPI
  628. CryptGenRandom(
  629.     HCRYPTPROV hProv,
  630.     DWORD dwLen,
  631.     BYTE *pbBuffer);
  632.  
  633. WINADVAPI
  634. BOOL
  635. WINAPI
  636. CryptGetUserKey(
  637.     HCRYPTPROV hProv,
  638.     DWORD dwKeySpec,
  639.     HCRYPTKEY *phUserKey);
  640.  
  641. WINADVAPI
  642. BOOL
  643. WINAPI
  644. CryptExportKey(
  645.     HCRYPTKEY hKey,
  646.     HCRYPTKEY hExpKey,
  647.     DWORD dwBlobType,
  648.     DWORD dwFlags,
  649.     BYTE *pbData,
  650.     DWORD *pdwDataLen);
  651.  
  652. WINADVAPI
  653. BOOL
  654. WINAPI
  655. CryptImportKey(
  656.     HCRYPTPROV hProv,
  657.     CONST BYTE *pbData,
  658.     DWORD dwDataLen,
  659.     HCRYPTKEY hPubKey,
  660.     DWORD dwFlags,
  661.     HCRYPTKEY *phKey);
  662.  
  663. WINADVAPI
  664. BOOL
  665. WINAPI
  666. CryptEncrypt(
  667.     HCRYPTKEY hKey,
  668.     HCRYPTHASH hHash,
  669.     BOOL Final,
  670.     DWORD dwFlags,
  671.     BYTE *pbData,
  672.     DWORD *pdwDataLen,
  673.     DWORD dwBufLen);
  674.  
  675. WINADVAPI
  676. BOOL
  677. WINAPI
  678. CryptDecrypt(
  679.     HCRYPTKEY hKey,
  680.     HCRYPTHASH hHash,
  681.     BOOL Final,
  682.     DWORD dwFlags,
  683.     BYTE *pbData,
  684.     DWORD *pdwDataLen);
  685.  
  686. WINADVAPI
  687. BOOL
  688. WINAPI
  689. CryptCreateHash(
  690.     HCRYPTPROV hProv,
  691.     ALG_ID Algid,
  692.     HCRYPTKEY hKey,
  693.     DWORD dwFlags,
  694.     HCRYPTHASH *phHash);
  695.  
  696. WINADVAPI
  697. BOOL
  698. WINAPI
  699. CryptHashData(
  700.     HCRYPTHASH hHash,
  701.     CONST BYTE *pbData,
  702.     DWORD dwDataLen,
  703.     DWORD dwFlags);
  704.  
  705. WINADVAPI
  706. BOOL
  707. WINAPI
  708. CryptHashSessionKey(
  709.     HCRYPTHASH hHash,
  710.     HCRYPTKEY hKey,
  711.     DWORD dwFlags);
  712.  
  713. WINADVAPI
  714. BOOL
  715. WINAPI
  716. CryptDestroyHash(
  717.     HCRYPTHASH hHash);
  718.  
  719. WINADVAPI
  720. BOOL
  721. WINAPI
  722. CryptSignHashA(
  723.     HCRYPTHASH hHash,
  724.     DWORD dwKeySpec,
  725.     LPCSTR sDescription,
  726.     DWORD dwFlags,
  727.     BYTE *pbSignature,
  728.     DWORD *pdwSigLen);
  729. WINADVAPI
  730. BOOL
  731. WINAPI
  732. CryptSignHashW(
  733.     HCRYPTHASH hHash,
  734.     DWORD dwKeySpec,
  735.     LPCWSTR sDescription,
  736.     DWORD dwFlags,
  737.     BYTE *pbSignature,
  738.     DWORD *pdwSigLen);
  739. #ifdef UNICODE
  740. #define CryptSignHash  CryptSignHashW
  741. #else
  742. #define CryptSignHash  CryptSignHashA
  743. #endif // !UNICODE
  744.  
  745. WINADVAPI
  746. BOOL
  747. WINAPI
  748. CryptVerifySignatureA(
  749.     HCRYPTHASH hHash,
  750.     CONST BYTE *pbSignature,
  751.     DWORD dwSigLen,
  752.     HCRYPTKEY hPubKey,
  753.     LPCSTR sDescription,
  754.     DWORD dwFlags);
  755. WINADVAPI
  756. BOOL
  757. WINAPI
  758. CryptVerifySignatureW(
  759.     HCRYPTHASH hHash,
  760.     CONST BYTE *pbSignature,
  761.     DWORD dwSigLen,
  762.     HCRYPTKEY hPubKey,
  763.     LPCWSTR sDescription,
  764.     DWORD dwFlags);
  765. #ifdef UNICODE
  766. #define CryptVerifySignature  CryptVerifySignatureW
  767. #else
  768. #define CryptVerifySignature  CryptVerifySignatureA
  769. #endif // !UNICODE
  770.  
  771. WINADVAPI
  772. BOOL
  773. WINAPI
  774. CryptSetProviderA(
  775.     LPCSTR pszProvName,
  776.     DWORD dwProvType);
  777. WINADVAPI
  778. BOOL
  779. WINAPI
  780. CryptSetProviderW(
  781.     LPCWSTR pszProvName,
  782.     DWORD dwProvType);
  783. #ifdef UNICODE
  784. #define CryptSetProvider  CryptSetProviderW
  785. #else
  786. #define CryptSetProvider  CryptSetProviderA
  787. #endif // !UNICODE
  788.  
  789. WINADVAPI
  790. BOOL
  791. WINAPI
  792. CryptSetProviderExA(
  793.     LPCSTR pszProvName,
  794.     DWORD dwProvType,
  795.     DWORD *pdwReserved,
  796.     DWORD dwFlags);
  797. WINADVAPI
  798. BOOL
  799. WINAPI
  800. CryptSetProviderExW(
  801.     LPCWSTR pszProvName,
  802.     DWORD dwProvType,
  803.     DWORD *pdwReserved,
  804.     DWORD dwFlags);
  805. #ifdef UNICODE
  806. #define CryptSetProviderEx  CryptSetProviderExW
  807. #else
  808. #define CryptSetProviderEx  CryptSetProviderExA
  809. #endif // !UNICODE
  810.  
  811. WINADVAPI
  812. BOOL
  813. WINAPI
  814. CryptGetDefaultProviderA(
  815.     DWORD dwProvType,
  816.     DWORD *pdwReserved,
  817.     DWORD dwFlags,
  818.     LPSTR pszProvName,
  819.     DWORD *pcbProvName);
  820. WINADVAPI
  821. BOOL
  822. WINAPI
  823. CryptGetDefaultProviderW(
  824.     DWORD dwProvType,
  825.     DWORD *pdwReserved,
  826.     DWORD dwFlags,
  827.     LPWSTR pszProvName,
  828.     DWORD *pcbProvName);
  829. #ifdef UNICODE
  830. #define CryptGetDefaultProvider  CryptGetDefaultProviderW
  831. #else
  832. #define CryptGetDefaultProvider  CryptGetDefaultProviderA
  833. #endif // !UNICODE
  834.  
  835. WINADVAPI
  836. BOOL
  837. WINAPI CryptEnumProviderTypesA(
  838.     DWORD dwIndex,
  839.     DWORD *pdwReserved,
  840.     DWORD dwFlags,
  841.     DWORD *pdwProvType,
  842.     LPSTR pszTypeName,
  843.     DWORD *pcbTypeName);
  844. WINADVAPI
  845. BOOL
  846. WINAPI CryptEnumProviderTypesW(
  847.     DWORD dwIndex,
  848.     DWORD *pdwReserved,
  849.     DWORD dwFlags,
  850.     DWORD *pdwProvType,
  851.     LPWSTR pszTypeName,
  852.     DWORD *pcbTypeName);
  853. #ifdef UNICODE
  854. #define CryptEnumProviderTypes  CryptEnumProviderTypesW
  855. #else
  856. #define CryptEnumProviderTypes  CryptEnumProviderTypesA
  857. #endif // !UNICODE
  858.  
  859. WINADVAPI
  860. BOOL
  861. WINAPI CryptEnumProvidersA(
  862.     DWORD dwIndex,
  863.     DWORD *pdwReserved,
  864.     DWORD dwFlags,
  865.     DWORD *pdwProvType,
  866.     LPSTR pszProvName,
  867.     DWORD *pcbProvName);
  868. WINADVAPI
  869. BOOL
  870. WINAPI CryptEnumProvidersW(
  871.     DWORD dwIndex,
  872.     DWORD *pdwReserved,
  873.     DWORD dwFlags,
  874.     DWORD *pdwProvType,
  875.     LPWSTR pszProvName,
  876.     DWORD *pcbProvName);
  877. #ifdef UNICODE
  878. #define CryptEnumProviders  CryptEnumProvidersW
  879. #else
  880. #define CryptEnumProviders  CryptEnumProvidersA
  881. #endif // !UNICODE
  882.  
  883. WINADVAPI
  884. BOOL
  885. WINAPI CryptContextAddRef(
  886.     HCRYPTPROV hProv,
  887.     DWORD *pdwReserved,
  888.     DWORD dwFlags);
  889.  
  890. WINADVAPI
  891. BOOL
  892. WINAPI CryptDuplicateKey(
  893.     HCRYPTKEY hKey,
  894.     DWORD *pdwReserved,
  895.     DWORD dwFlags,
  896.     HCRYPTKEY * phKey);
  897.  
  898. WINADVAPI
  899. BOOL
  900. WINAPI CryptDuplicateHash(
  901.     HCRYPTHASH hHash,
  902.     DWORD *pdwReserved,
  903.     DWORD dwFlags,
  904.     HCRYPTHASH * phHash);
  905.  
  906. //+-------------------------------------------------------------------------
  907. //  CRYPTOAPI BLOB definitions
  908. //--------------------------------------------------------------------------
  909. typedef struct _CRYPTOAPI_BLOB {
  910.     DWORD   cbData;
  911.     BYTE    *pbData;
  912. } CRYPT_INTEGER_BLOB, *PCRYPT_INTEGER_BLOB,
  913.   CRYPT_UINT_BLOB, *PCRYPT_UINT_BLOB,
  914.   CRYPT_OBJID_BLOB, *PCRYPT_OBJID_BLOB,
  915.   CERT_NAME_BLOB, *PCERT_NAME_BLOB,
  916.   CERT_RDN_VALUE_BLOB, *PCERT_RDN_VALUE_BLOB,
  917.   CERT_BLOB, *PCERT_BLOB,
  918.   CRL_BLOB, *PCRL_BLOB,
  919.   DATA_BLOB, *PDATA_BLOB,                   // JEFFJEFF temporary (too generic)
  920.   CRYPT_DATA_BLOB, *PCRYPT_DATA_BLOB,
  921.   CRYPT_HASH_BLOB, *PCRYPT_HASH_BLOB,
  922.   CRYPT_DIGEST_BLOB, *PCRYPT_DIGEST_BLOB,
  923.   CRYPT_DER_BLOB, *PCRYPT_DER_BLOB,
  924.   CRYPT_ATTR_BLOB, *PCRYPT_ATTR_BLOB;
  925.  
  926. //+-------------------------------------------------------------------------
  927. //  In a CRYPT_BIT_BLOB the last byte may contain 0-7 unused bits. Therefore, the
  928. //  overall bit length is cbData * 8 - cUnusedBits.
  929. //--------------------------------------------------------------------------
  930. typedef struct _CRYPT_BIT_BLOB {
  931.     DWORD   cbData;
  932.     BYTE    *pbData;
  933.     DWORD   cUnusedBits;
  934. } CRYPT_BIT_BLOB, *PCRYPT_BIT_BLOB;
  935.  
  936. //+-------------------------------------------------------------------------
  937. //  Type used for any algorithm
  938. //
  939. //  Where the Parameters CRYPT_OBJID_BLOB is in its encoded representation. For most
  940. //  algorithm types, the Parameters CRYPT_OBJID_BLOB is NULL (Parameters.cbData = 0).
  941. //--------------------------------------------------------------------------
  942. typedef struct _CRYPT_ALGORITHM_IDENTIFIER {
  943.     LPSTR               pszObjId;
  944.     CRYPT_OBJID_BLOB    Parameters;
  945. } CRYPT_ALGORITHM_IDENTIFIER, *PCRYPT_ALGORITHM_IDENTIFIER;
  946.  
  947. // Following are the definitions of various algorithm object identifiers
  948. // RSA
  949. #define szOID_RSA               "1.2.840.113549"
  950. #define szOID_PKCS              "1.2.840.113549.1"
  951. #define szOID_RSA_HASH          "1.2.840.113549.2"
  952. #define szOID_RSA_ENCRYPT       "1.2.840.113549.3"
  953.  
  954. #define szOID_PKCS_1            "1.2.840.113549.1.1"
  955. #define szOID_PKCS_2            "1.2.840.113549.1.2"
  956. #define szOID_PKCS_3            "1.2.840.113549.1.3"
  957. #define szOID_PKCS_4            "1.2.840.113549.1.4"
  958. #define szOID_PKCS_5            "1.2.840.113549.1.5"
  959. #define szOID_PKCS_6            "1.2.840.113549.1.6"
  960. #define szOID_PKCS_7            "1.2.840.113549.1.7"
  961. #define szOID_PKCS_8            "1.2.840.113549.1.8"
  962. #define szOID_PKCS_9            "1.2.840.113549.1.9"
  963. #define szOID_PKCS_10           "1.2.840.113549.1.10"
  964.  
  965. #define szOID_RSA_RSA           "1.2.840.113549.1.1.1"
  966. #define szOID_RSA_MD2RSA        "1.2.840.113549.1.1.2"
  967. #define szOID_RSA_MD4RSA        "1.2.840.113549.1.1.3"
  968. #define szOID_RSA_MD5RSA        "1.2.840.113549.1.1.4"
  969. #define szOID_RSA_SHA1RSA       "1.2.840.113549.1.1.5"
  970. #define szOID_RSA_SETOAEP_RSA   "1.2.840.113549.1.1.6"
  971.  
  972. #define szOID_RSA_data          "1.2.840.113549.1.7.1"
  973. #define szOID_RSA_signedData    "1.2.840.113549.1.7.2"
  974. #define szOID_RSA_envelopedData "1.2.840.113549.1.7.3"
  975. #define szOID_RSA_signEnvData   "1.2.840.113549.1.7.4"
  976. #define szOID_RSA_digestedData  "1.2.840.113549.1.7.5"
  977. #define szOID_RSA_hashedData    "1.2.840.113549.1.7.5"
  978. #define szOID_RSA_encryptedData "1.2.840.113549.1.7.6"
  979.  
  980. #define szOID_RSA_emailAddr     "1.2.840.113549.1.9.1"
  981. #define szOID_RSA_unstructName  "1.2.840.113549.1.9.2"
  982. #define szOID_RSA_contentType   "1.2.840.113549.1.9.3"
  983. #define szOID_RSA_messageDigest "1.2.840.113549.1.9.4"
  984. #define szOID_RSA_signingTime   "1.2.840.113549.1.9.5"
  985. #define szOID_RSA_counterSign   "1.2.840.113549.1.9.6"
  986. #define szOID_RSA_challengePwd  "1.2.840.113549.1.9.7"
  987. #define szOID_RSA_unstructAddr  "1.2.840.113549.1.9.8"
  988. #define szOID_RSA_extCertAttrs  "1.2.840.113549.1.9.9"
  989. #define szOID_RSA_SMIMECapabilities "1.2.840.113549.1.9.15"
  990. #define szOID_RSA_preferSignedData "1.2.840.113549.1.9.15.1"
  991.  
  992. #define szOID_RSA_MD2           "1.2.840.113549.2.2"
  993. #define szOID_RSA_MD4           "1.2.840.113549.2.4"
  994. #define szOID_RSA_MD5           "1.2.840.113549.2.5"
  995.  
  996. #define szOID_RSA_RC2CBC        "1.2.840.113549.3.2"
  997. #define szOID_RSA_RC4           "1.2.840.113549.3.4"
  998. #define szOID_RSA_DES_EDE3_CBC  "1.2.840.113549.3.7"
  999. #define szOID_RSA_RC5_CBCPad    "1.2.840.113549.3.9"
  1000.  
  1001. // ITU-T UsefulDefinitions
  1002. #define szOID_DS                "2.5"
  1003. #define szOID_DSALG             "2.5.8"
  1004. #define szOID_DSALG_CRPT        "2.5.8.1"
  1005. #define szOID_DSALG_HASH        "2.5.8.2"
  1006. #define szOID_DSALG_SIGN        "2.5.8.3"
  1007. #define szOID_DSALG_RSA         "2.5.8.1.1"
  1008. // NIST OSE Implementors' Workshop (OIW)
  1009. // http://nemo.ncsl.nist.gov/oiw/agreements/stable/OSI/12s_9506.w51
  1010. // http://nemo.ncsl.nist.gov/oiw/agreements/working/OSI/12w_9503.w51
  1011. #define szOID_OIW               "1.3.14"
  1012. // NIST OSE Implementors' Workshop (OIW) Security SIG algorithm identifiers
  1013. #define szOID_OIWSEC            "1.3.14.3.2"
  1014. #define szOID_OIWSEC_md4RSA     "1.3.14.3.2.2"
  1015. #define szOID_OIWSEC_md5RSA     "1.3.14.3.2.3"
  1016. #define szOID_OIWSEC_md4RSA2    "1.3.14.3.2.4"
  1017. #define szOID_OIWSEC_desECB     "1.3.14.3.2.6"
  1018. #define szOID_OIWSEC_desCBC     "1.3.14.3.2.7"
  1019. #define szOID_OIWSEC_desOFB     "1.3.14.3.2.8"
  1020. #define szOID_OIWSEC_desCFB     "1.3.14.3.2.9"
  1021. #define szOID_OIWSEC_desMAC     "1.3.14.3.2.10"
  1022. #define szOID_OIWSEC_rsaSign    "1.3.14.3.2.11"
  1023. #define szOID_OIWSEC_dsa        "1.3.14.3.2.12"
  1024. #define szOID_OIWSEC_shaDSA     "1.3.14.3.2.13"
  1025. #define szOID_OIWSEC_mdc2RSA    "1.3.14.3.2.14"
  1026. #define szOID_OIWSEC_shaRSA     "1.3.14.3.2.15"
  1027. #define szOID_OIWSEC_dhCommMod  "1.3.14.3.2.16"
  1028. #define szOID_OIWSEC_desEDE     "1.3.14.3.2.17"
  1029. #define szOID_OIWSEC_sha        "1.3.14.3.2.18"
  1030. #define szOID_OIWSEC_mdc2       "1.3.14.3.2.19"
  1031. #define szOID_OIWSEC_dsaComm    "1.3.14.3.2.20"
  1032. #define szOID_OIWSEC_dsaCommSHA "1.3.14.3.2.21"
  1033. #define szOID_OIWSEC_rsaXchg    "1.3.14.3.2.22"
  1034. #define szOID_OIWSEC_keyHashSeal "1.3.14.3.2.23"
  1035. #define szOID_OIWSEC_md2RSASign "1.3.14.3.2.24"
  1036. #define szOID_OIWSEC_md5RSASign "1.3.14.3.2.25"
  1037. #define szOID_OIWSEC_sha1       "1.3.14.3.2.26"
  1038. #define szOID_OIWSEC_dsaSHA1    "1.3.14.3.2.27"
  1039. #define szOID_OIWSEC_dsaCommSHA1 "1.3.14.3.2.28"
  1040. #define szOID_OIWSEC_sha1RSASign "1.3.14.3.2.29"
  1041. // NIST OSE Implementors' Workshop (OIW) Directory SIG algorithm identifiers
  1042. #define szOID_OIWDIR            "1.3.14.7.2"
  1043. #define szOID_OIWDIR_CRPT       "1.3.14.7.2.1"
  1044. #define szOID_OIWDIR_HASH       "1.3.14.7.2.2"
  1045. #define szOID_OIWDIR_SIGN       "1.3.14.7.2.3"
  1046. #define szOID_OIWDIR_md2        "1.3.14.7.2.2.1"
  1047. #define szOID_OIWDIR_md2RSA     "1.3.14.7.2.3.1"
  1048.  
  1049.  
  1050. // INFOSEC Algorithms
  1051. // joint-iso-ccitt(2) country(16) us(840) organization(1) us-government(101) dod(2) id-infosec(1)
  1052. #define szOID_INFOSEC                       "2.16.840.1.101.2.1"
  1053. #define szOID_INFOSEC_sdnsSignature         "2.16.840.1.101.2.1.1.1"
  1054. #define szOID_INFOSEC_mosaicSignature       "2.16.840.1.101.2.1.1.2"
  1055. #define szOID_INFOSEC_sdnsConfidentiality   "2.16.840.1.101.2.1.1.3"
  1056. #define szOID_INFOSEC_mosaicConfidentiality "2.16.840.1.101.2.1.1.4"
  1057. #define szOID_INFOSEC_sdnsIntegrity         "2.16.840.1.101.2.1.1.5"
  1058. #define szOID_INFOSEC_mosaicIntegrity       "2.16.840.1.101.2.1.1.6"
  1059. #define szOID_INFOSEC_sdnsTokenProtection   "2.16.840.1.101.2.1.1.7"
  1060. #define szOID_INFOSEC_mosaicTokenProtection "2.16.840.1.101.2.1.1.8"
  1061. #define szOID_INFOSEC_sdnsKeyManagement     "2.16.840.1.101.2.1.1.9"
  1062. #define szOID_INFOSEC_mosaicKeyManagement   "2.16.840.1.101.2.1.1.10"
  1063. #define szOID_INFOSEC_sdnsKMandSig          "2.16.840.1.101.2.1.1.11"
  1064. #define szOID_INFOSEC_mosaicKMandSig        "2.16.840.1.101.2.1.1.12"
  1065. #define szOID_INFOSEC_SuiteASignature       "2.16.840.1.101.2.1.1.13"
  1066. #define szOID_INFOSEC_SuiteAConfidentiality "2.16.840.1.101.2.1.1.14"
  1067. #define szOID_INFOSEC_SuiteAIntegrity       "2.16.840.1.101.2.1.1.15"
  1068. #define szOID_INFOSEC_SuiteATokenProtection "2.16.840.1.101.2.1.1.16"
  1069. #define szOID_INFOSEC_SuiteAKeyManagement   "2.16.840.1.101.2.1.1.17"
  1070. #define szOID_INFOSEC_SuiteAKMandSig        "2.16.840.1.101.2.1.1.18"
  1071. #define szOID_INFOSEC_mosaicUpdatedSig      "2.16.840.1.101.2.1.1.19"
  1072. #define szOID_INFOSEC_mosaicKMandUpdSig     "2.16.840.1.101.2.1.1.20"
  1073. #define szOID_INFOSEC_mosaicUpdatedInteg    "2.16.840.1.101.2.1.1.21"
  1074.  
  1075. typedef struct _CRYPT_OBJID_TABLE {
  1076.     DWORD   dwAlgId;
  1077.     LPCSTR  pszObjId;
  1078. } CRYPT_OBJID_TABLE, *PCRYPT_OBJID_TABLE;
  1079.  
  1080.  
  1081. //+-------------------------------------------------------------------------
  1082. //  PKCS #1 HashInfo (DigestInfo)
  1083. //--------------------------------------------------------------------------
  1084. typedef struct _CRYPT_HASH_INFO {
  1085.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  1086.     CRYPT_HASH_BLOB             Hash;
  1087. } CRYPT_HASH_INFO, *PCRYPT_HASH_INFO;
  1088.  
  1089. //+-------------------------------------------------------------------------
  1090. //  Type used for an extension to an encoded content
  1091. //
  1092. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1093. //--------------------------------------------------------------------------
  1094. typedef struct _CERT_EXTENSION {
  1095.     LPSTR               pszObjId;
  1096.     BOOL                fCritical;
  1097.     CRYPT_OBJID_BLOB    Value;
  1098. } CERT_EXTENSION, *PCERT_EXTENSION;
  1099.  
  1100. //+-------------------------------------------------------------------------
  1101. //  AttributeTypeValue
  1102. //
  1103. //  Where the Value's CRYPT_OBJID_BLOB is in its encoded representation.
  1104. //--------------------------------------------------------------------------
  1105. typedef struct _CRYPT_ATTRIBUTE_TYPE_VALUE {
  1106.     LPSTR               pszObjId;
  1107.     CRYPT_OBJID_BLOB    Value;
  1108. } CRYPT_ATTRIBUTE_TYPE_VALUE, *PCRYPT_ATTRIBUTE_TYPE_VALUE;
  1109.  
  1110. //+-------------------------------------------------------------------------
  1111. //  Attributes
  1112. //
  1113. //  Where the Value's PATTR_BLOBs are in their encoded representation.
  1114. //--------------------------------------------------------------------------
  1115. typedef struct _CRYPT_ATTRIBUTE {
  1116.     LPSTR               pszObjId;
  1117.     DWORD               cValue;
  1118.     PCRYPT_ATTR_BLOB    rgValue;
  1119. } CRYPT_ATTRIBUTE, *PCRYPT_ATTRIBUTE;
  1120.  
  1121. typedef struct _CRYPT_ATTRIBUTES {
  1122.     IN DWORD                cAttr;
  1123.     IN PCRYPT_ATTRIBUTE     rgAttr;
  1124. } CRYPT_ATTRIBUTES, *PCRYPT_ATTRIBUTES;
  1125.  
  1126. //+-------------------------------------------------------------------------
  1127. //  Attributes making up a Relative Distinguished Name (CERT_RDN)
  1128. //
  1129. //  The interpretation of the Value depends on the dwValueType.
  1130. //  See below for a list of the types.
  1131. //--------------------------------------------------------------------------
  1132. typedef struct _CERT_RDN_ATTR {
  1133.     LPSTR                   pszObjId;
  1134.     DWORD                   dwValueType;
  1135.     CERT_RDN_VALUE_BLOB     Value;
  1136. } CERT_RDN_ATTR, *PCERT_RDN_ATTR;
  1137.  
  1138. //+-------------------------------------------------------------------------
  1139. //  CERT_RDN attribute Object Identifiers
  1140. //--------------------------------------------------------------------------
  1141. // Labeling attribute types:
  1142. #define szOID_COMMON_NAME                   "2.5.4.3"  // case-ignore string
  1143. #define szOID_SUR_NAME                      "2.5.4.4"  // case-ignore string
  1144. #define szOID_DEVICE_SERIAL_NUMBER          "2.5.4.5"  // printable string
  1145.  
  1146. // Geographic attribute types:
  1147. #define szOID_COUNTRY_NAME                  "2.5.4.6"  // printable 2char string
  1148. #define szOID_LOCALITY_NAME                 "2.5.4.7"  // case-ignore string
  1149. #define szOID_STATE_OR_PROVINCE_NAME        "2.5.4.8"  // case-ignore string
  1150. #define szOID_STREET_ADDRESS                "2.5.4.9"  // case-ignore string
  1151.  
  1152. // Organizational attribute types:
  1153. #define szOID_ORGANIZATION_NAME             "2.5.4.10" // case-ignore string
  1154. #define szOID_ORGANIZATIONAL_UNIT_NAME      "2.5.4.11" // case-ignore string
  1155. #define szOID_TITLE                         "2.5.4.12" // case-ignore string
  1156.  
  1157. // Explanatory attribute types:
  1158. #define szOID_DESCRIPTION                   "2.5.4.13" // case-ignore string
  1159. #define szOID_SEARCH_GUIDE                  "2.5.4.14"
  1160. #define szOID_BUSINESS_CATEGORY             "2.5.4.15" // case-ignore string
  1161.  
  1162. // Postal addressing attribute types:
  1163. #define szOID_POSTAL_ADDRESS                "2.5.4.16"
  1164. #define szOID_POSTAL_CODE                   "2.5.4.17" // case-ignore string
  1165. #define szOID_POST_OFFICE_BOX               "2.5.4.18" // case-ignore string
  1166. #define szOID_PHYSICAL_DELIVERY_OFFICE_NAME "2.5.4.19" // case-ignore string
  1167.  
  1168. // Telecommunications addressing attribute types:
  1169. #define szOID_TELEPHONE_NUMBER              "2.5.4.20" // telephone number
  1170. #define szOID_TELEX_NUMBER                  "2.5.4.21"
  1171. #define szOID_TELETEXT_TERMINAL_IDENTIFIER  "2.5.4.22"
  1172. #define szOID_FACSIMILE_TELEPHONE_NUMBER    "2.5.4.23"
  1173. #define szOID_X21_ADDRESS                   "2.5.4.24" // numeric string
  1174. #define szOID_INTERNATIONAL_ISDN_NUMBER     "2.5.4.25" // numeric string
  1175. #define szOID_REGISTERED_ADDRESS            "2.5.4.26"
  1176. #define szOID_DESTINATION_INDICATOR         "2.5.4.27" // printable string
  1177.  
  1178. // Preference attribute types:
  1179. #define szOID_PREFERRED_DELIVERY_METHOD     "2.5.4.28"
  1180.  
  1181. // OSI application attribute types:
  1182. #define szOID_PRESENTATION_ADDRESS          "2.5.4.29"
  1183. #define szOID_SUPPORTED_APPLICATION_CONTEXT "2.5.4.30"
  1184.  
  1185. // Relational application attribute types:
  1186. #define szOID_MEMBER                        "2.5.4.31"
  1187. #define szOID_OWNER                         "2.5.4.32"
  1188. #define szOID_ROLE_OCCUPANT                 "2.5.4.33"
  1189. #define szOID_SEE_ALSO                      "2.5.4.34"
  1190.  
  1191. // Security attribute types:
  1192. #define szOID_USER_PASSWORD                 "2.5.4.35"
  1193. #define szOID_USER_CERTIFICATE              "2.5.4.36"
  1194. #define szOID_CA_CERTIFICATE                "2.5.4.37"
  1195. #define szOID_AUTHORITY_REVOCATION_LIST     "2.5.4.38"
  1196. #define szOID_CERTIFICATE_REVOCATION_LIST   "2.5.4.39"
  1197. #define szOID_CROSS_CERTIFICATE_PAIR        "2.5.4.40"
  1198.  
  1199. // Undocumented attribute types???
  1200. //#define szOID_???                         "2.5.4.41"
  1201. #define szOID_GIVEN_NAME                    "2.5.4.42" // case-ignore string
  1202. #define szOID_INITIALS                      "2.5.4.43" // case-ignore string
  1203.  
  1204. // Pilot user attribute types:
  1205. #define szOID_DOMAIN_COMPONENT  "0.9.2342.19200300.100.1.25" // IA5 string
  1206.  
  1207. //+-------------------------------------------------------------------------
  1208. //  CERT_RDN Attribute Value Types
  1209. //
  1210. //  For RDN_ENCODED_BLOB, the Value's CERT_RDN_VALUE_BLOB is in its encoded
  1211. //  representation. Otherwise, its an array of bytes.
  1212. //
  1213. //  For all CERT_RDN types, Value.cbData is always the number of bytes, not
  1214. //  necessarily the number of elements in the string. For instance,
  1215. //  RDN_UNIVERSAL_STRING is an array of ints (cbData == intCnt * 4) and
  1216. //  RDN_BMP_STRING is an array of unsigned shorts (cbData == ushortCnt * 2).
  1217. //
  1218. //  For CertDecodeName, two 0 bytes are always appended to the end of the
  1219. //  string (ensures a CHAR or WCHAR string is null terminated).
  1220. //  These added 0 bytes are't included in the BLOB.cbData.
  1221. //--------------------------------------------------------------------------
  1222. #define CERT_RDN_ANY_TYPE                0
  1223. #define CERT_RDN_ENCODED_BLOB            1
  1224. #define CERT_RDN_OCTET_STRING            2
  1225. #define CERT_RDN_NUMERIC_STRING          3
  1226. #define CERT_RDN_PRINTABLE_STRING        4
  1227. #define CERT_RDN_TELETEX_STRING          5
  1228. #define CERT_RDN_T61_STRING              5
  1229. #define CERT_RDN_VIDEOTEX_STRING         6
  1230. #define CERT_RDN_IA5_STRING              7
  1231. #define CERT_RDN_GRAPHIC_STRING          8
  1232. #define CERT_RDN_VISIBLE_STRING          9
  1233. #define CERT_RDN_ISO646_STRING           9
  1234. #define CERT_RDN_GENERAL_STRING          10
  1235. #define CERT_RDN_UNIVERSAL_STRING        11
  1236. #define CERT_RDN_INT4_STRING             11
  1237. #define CERT_RDN_BMP_STRING              12
  1238. #define CERT_RDN_UNICODE_STRING          12
  1239.  
  1240.  
  1241. // Macro to check that the dwValueType is a character string and not an
  1242. // encoded blob or octet string
  1243. #define IS_CERT_RDN_CHAR_STRING(X) (X >= CERT_RDN_NUMERIC_STRING)
  1244.  
  1245. //+-------------------------------------------------------------------------
  1246. //  A CERT_RDN consists of an array of the above attributes
  1247. //--------------------------------------------------------------------------
  1248. typedef struct _CERT_RDN {
  1249.     DWORD           cRDNAttr;
  1250.     PCERT_RDN_ATTR  rgRDNAttr;
  1251. } CERT_RDN, *PCERT_RDN;
  1252.  
  1253. //+-------------------------------------------------------------------------
  1254. //  Information stored in a subject's or issuer's name. The information
  1255. //  is represented as an array of the above RDNs.
  1256. //--------------------------------------------------------------------------
  1257. typedef struct _CERT_NAME_INFO {
  1258.     DWORD       cRDN;
  1259.     PCERT_RDN   rgRDN;
  1260. } CERT_NAME_INFO, *PCERT_NAME_INFO;
  1261.  
  1262. //+-------------------------------------------------------------------------
  1263. //  Name attribute value without the Object Identifier
  1264. //
  1265. //  The interpretation of the Value depends on the dwValueType.
  1266. //  See above for a list of the types.
  1267. //--------------------------------------------------------------------------
  1268. typedef struct _CERT_NAME_VALUE {
  1269.     DWORD               dwValueType;
  1270.     CERT_RDN_VALUE_BLOB Value;
  1271. } CERT_NAME_VALUE, *PCERT_NAME_VALUE;
  1272.  
  1273. //+-------------------------------------------------------------------------
  1274. //  Public Key Info
  1275. //
  1276. //  The PublicKey is the encoded representation of the information as it is
  1277. //  stored in the bit string
  1278. //--------------------------------------------------------------------------
  1279. typedef struct _CERT_PUBLIC_KEY_INFO {
  1280.     CRYPT_ALGORITHM_IDENTIFIER    Algorithm;
  1281.     CRYPT_BIT_BLOB                PublicKey;
  1282. } CERT_PUBLIC_KEY_INFO, *PCERT_PUBLIC_KEY_INFO;
  1283.  
  1284. #define CERT_RSA_PUBLIC_KEY_OBJID            szOID_RSA_RSA
  1285. #define CERT_DEFAULT_OID_PUBLIC_KEY_SIGN     szOID_RSA_RSA
  1286. #define CERT_DEFAULT_OID_PUBLIC_KEY_XCHG     szOID_RSA_RSA
  1287.  
  1288. //+-------------------------------------------------------------------------
  1289. //  Information stored in a certificate
  1290. //
  1291. //  The Issuer, Subject, Algorithm, PublicKey and Extension BLOBs are the
  1292. //  encoded representation of the information.
  1293. //--------------------------------------------------------------------------
  1294. typedef struct _CERT_INFO {
  1295.     DWORD                       dwVersion;
  1296.     CRYPT_INTEGER_BLOB          SerialNumber;
  1297.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1298.     CERT_NAME_BLOB              Issuer;
  1299.     FILETIME                    NotBefore;
  1300.     FILETIME                    NotAfter;
  1301.     CERT_NAME_BLOB              Subject;
  1302.     CERT_PUBLIC_KEY_INFO        SubjectPublicKeyInfo;
  1303.     CRYPT_BIT_BLOB              IssuerUniqueId;
  1304.     CRYPT_BIT_BLOB              SubjectUniqueId;
  1305.     DWORD                       cExtension;
  1306.     PCERT_EXTENSION             rgExtension;
  1307. } CERT_INFO, *PCERT_INFO;
  1308.  
  1309. //+-------------------------------------------------------------------------
  1310. //  Certificate versions
  1311. //--------------------------------------------------------------------------
  1312. #define CERT_V1     0
  1313. #define CERT_V2     1
  1314. #define CERT_V3     2
  1315.  
  1316. //+-------------------------------------------------------------------------
  1317. //  Certificate Information Flags
  1318. //--------------------------------------------------------------------------
  1319. #define CERT_INFO_VERSION_FLAG                      1
  1320. #define CERT_INFO_SERIAL_NUMBER_FLAG                2
  1321. #define CERT_INFO_SIGNATURE_ALGORITHM_FLAG          3
  1322. #define CERT_INFO_ISSUER_FLAG                       4
  1323. #define CERT_INFO_NOT_BEFORE_FLAG                   5
  1324. #define CERT_INFO_NOT_AFTER_FLAG                    6
  1325. #define CERT_INFO_SUBJECT_FLAG                      7
  1326. #define CERT_INFO_SUBJECT_PUBLIC_KEY_INFO_FLAG      8
  1327. #define CERT_INFO_ISSUER_UNIQUE_ID_FLAG             9
  1328. #define CERT_INFO_SUBJECT_UNIQUE_ID_FLAG            10
  1329. #define CERT_INFO_EXTENSION_FLAG                    11
  1330.  
  1331. //+-------------------------------------------------------------------------
  1332. //  An entry in a CRL
  1333. //
  1334. //  The Extension BLOBs are the encoded representation of the information.
  1335. //--------------------------------------------------------------------------
  1336. typedef struct _CRL_ENTRY {
  1337.     CRYPT_INTEGER_BLOB  SerialNumber;
  1338.     FILETIME            RevocationDate;
  1339.     DWORD               cExtension;
  1340.     PCERT_EXTENSION     rgExtension;
  1341. } CRL_ENTRY, *PCRL_ENTRY;
  1342.  
  1343. //+-------------------------------------------------------------------------
  1344. //  Information stored in a CRL
  1345. //
  1346. //  The Issuer, Algorithm and Extension BLOBs are the encoded
  1347. //  representation of the information.
  1348. //--------------------------------------------------------------------------
  1349. typedef struct _CRL_INFO {
  1350.     DWORD                       dwVersion;
  1351.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1352.     CERT_NAME_BLOB              Issuer;
  1353.     FILETIME                    ThisUpdate;
  1354.     FILETIME                    NextUpdate;
  1355.     DWORD                       cCRLEntry;
  1356.     PCRL_ENTRY                  rgCRLEntry;
  1357.     DWORD                       cExtension;
  1358.     PCERT_EXTENSION             rgExtension;
  1359. } CRL_INFO, *PCRL_INFO;
  1360.  
  1361. //+-------------------------------------------------------------------------
  1362. //  CRL versions
  1363. //--------------------------------------------------------------------------
  1364. #define CRL_V1     0
  1365. #define CRL_V2     1
  1366.  
  1367.  
  1368. //+-------------------------------------------------------------------------
  1369. //  Information stored in a certificate request
  1370. //
  1371. //  The Subject, Algorithm, PublicKey and Attribute BLOBs are the encoded
  1372. //  representation of the information.
  1373. //--------------------------------------------------------------------------
  1374. typedef struct _CERT_REQUEST_INFO {
  1375.     DWORD                   dwVersion;
  1376.     CERT_NAME_BLOB          Subject;
  1377.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1378.     DWORD                   cAttribute;
  1379.     PCRYPT_ATTRIBUTE        rgAttribute;
  1380. } CERT_REQUEST_INFO, *PCERT_REQUEST_INFO;
  1381.  
  1382. //+-------------------------------------------------------------------------
  1383. //  Certificate Request versions
  1384. //--------------------------------------------------------------------------
  1385. #define CERT_REQUEST_V1     0
  1386.  
  1387. //+-------------------------------------------------------------------------
  1388. //  Information stored in Netscape's Keygen request
  1389. //--------------------------------------------------------------------------
  1390. typedef struct _CERT_KEYGEN_REQUEST_INFO {
  1391.     DWORD                   dwVersion;
  1392.     CERT_PUBLIC_KEY_INFO    SubjectPublicKeyInfo;
  1393.     LPWSTR                  pwszChallengeString;        // encoded as IA5
  1394. } CERT_KEYGEN_REQUEST_INFO, *PCERT_KEYGEN_REQUEST_INFO;
  1395.  
  1396. #define CERT_KEYGEN_REQUEST_V1     0
  1397.  
  1398.  
  1399. //+-------------------------------------------------------------------------
  1400. //  Certificate, CRL, Certificate Request or Keygen Request Signed Content
  1401. //
  1402. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1403. //  is the encoded CERT_INFO, CRL_INFO, CERT_REQUEST_INFO or
  1404. //  CERT_KEYGEN_REQUEST_INFO.
  1405. //--------------------------------------------------------------------------
  1406. typedef struct _CERT_SIGNED_CONTENT_INFO {
  1407.     CRYPT_DER_BLOB              ToBeSigned;
  1408.     CRYPT_ALGORITHM_IDENTIFIER  SignatureAlgorithm;
  1409.     CRYPT_BIT_BLOB              Signature;
  1410. } CERT_SIGNED_CONTENT_INFO, *PCERT_SIGNED_CONTENT_INFO;
  1411.  
  1412.  
  1413. //+-------------------------------------------------------------------------
  1414. //  Certificate Trust List (CTL)
  1415. //--------------------------------------------------------------------------
  1416.  
  1417. //+-------------------------------------------------------------------------
  1418. //  CTL Usage. Also used for EnhancedKeyUsage extension.
  1419. //--------------------------------------------------------------------------
  1420. typedef struct _CTL_USAGE {
  1421.     DWORD               cUsageIdentifier;
  1422.     LPSTR               *rgpszUsageIdentifier;      // array of pszObjId
  1423. } CTL_USAGE, *PCTL_USAGE,
  1424.   CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
  1425.  
  1426.  
  1427. //+-------------------------------------------------------------------------
  1428. //  An entry in a CTL
  1429. //--------------------------------------------------------------------------
  1430. typedef struct _CTL_ENTRY {
  1431.     CRYPT_DATA_BLOB     SubjectIdentifier;          // For example, its hash
  1432.     DWORD               cAttribute;
  1433.     PCRYPT_ATTRIBUTE    rgAttribute;                // OPTIONAL
  1434. } CTL_ENTRY, *PCTL_ENTRY;
  1435.  
  1436. //+-------------------------------------------------------------------------
  1437. //  Information stored in a CTL
  1438. //--------------------------------------------------------------------------
  1439. typedef struct _CTL_INFO {
  1440.     DWORD                       dwVersion;
  1441.     CTL_USAGE                   SubjectUsage;
  1442.     CRYPT_DATA_BLOB             ListIdentifier;     // OPTIONAL
  1443.     CRYPT_INTEGER_BLOB          SequenceNumber;     // OPTIONAL
  1444.     FILETIME                    ThisUpdate;
  1445.     FILETIME                    NextUpdate;         // OPTIONAL
  1446.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  1447.     DWORD                       cCTLEntry;
  1448.     PCTL_ENTRY                  rgCTLEntry;         // OPTIONAL
  1449.     DWORD                       cExtension;
  1450.     PCERT_EXTENSION             rgExtension;        // OPTIONAL
  1451. } CTL_INFO, *PCTL_INFO;
  1452.  
  1453. //+-------------------------------------------------------------------------
  1454. //  CTL versions
  1455. //--------------------------------------------------------------------------
  1456. #define CTL_V1     0
  1457.  
  1458.  
  1459. //+-------------------------------------------------------------------------
  1460. //  TimeStamp Request
  1461. //
  1462. //  The pszTimeStamp is the OID for the Time type requested
  1463. //  The pszContentType is the Content Type OID for the content, usually DATA
  1464. //  The Content is a un-decoded blob
  1465. //--------------------------------------------------------------------------
  1466. typedef struct _CRYPT_TIME_STAMP_REQUEST_INFO {
  1467.     LPSTR                   pszTimeStampAlgorithm;   // pszObjId
  1468.     LPSTR                   pszContentType;          // pszObjId
  1469.     CRYPT_OBJID_BLOB        Content;
  1470.     DWORD                   cAttribute;
  1471.     PCRYPT_ATTRIBUTE        rgAttribute;
  1472. } CRYPT_TIME_STAMP_REQUEST_INFO, *PCRYPT_TIME_STAMP_REQUEST_INFO;
  1473.  
  1474. //+-------------------------------------------------------------------------
  1475. //  Certificate and Message encoding types
  1476. //
  1477. //  The encoding type is a DWORD containing both the certificate and message
  1478. //  encoding types. The certificate encoding type is stored in the LOWORD.
  1479. //  The message encoding type is stored in the HIWORD. Some functions or
  1480. //  structure fields require only one of the encoding types. The following
  1481. //  naming convention is used to indicate which encoding type(s) are
  1482. //  required:
  1483. //      dwEncodingType              (both encoding types are required)
  1484. //      dwMsgAndCertEncodingType    (both encoding types are required)
  1485. //      dwMsgEncodingType           (only msg encoding type is required)
  1486. //      dwCertEncodingType          (only cert encoding type is required)
  1487. //
  1488. //  Its always acceptable to specify both.
  1489. //--------------------------------------------------------------------------
  1490. #define CERT_ENCODING_TYPE_MASK     0x0000FFFF
  1491. #define CMSG_ENCODING_TYPE_MASK     0xFFFF0000
  1492. #define GET_CERT_ENCODING_TYPE(X)   (X & CERT_ENCODING_TYPE_MASK)
  1493. #define GET_CMSG_ENCODING_TYPE(X)   (X & CMSG_ENCODING_TYPE_MASK)
  1494.  
  1495. #define CRYPT_ASN_ENCODING          0x00000001
  1496. #define CRYPT_NDR_ENCODING          0x00000002
  1497. #define X509_ASN_ENCODING           0x00000001
  1498. #define X509_NDR_ENCODING           0x00000002
  1499. #define PKCS_7_ASN_ENCODING         0x00010000
  1500. #define PKCS_7_NDR_ENCODING         0x00020000
  1501.  
  1502.  
  1503. //+-------------------------------------------------------------------------
  1504. //  format the specified data structure according to the certificate
  1505. //  encoding type.
  1506. //
  1507. //--------------------------------------------------------------------------
  1508. WINCRYPT32API
  1509. BOOL
  1510. WINAPI
  1511. CryptFormatObject(
  1512.     IN DWORD dwCertEncodingType,
  1513.     IN DWORD dwFormatType,
  1514.     IN DWORD dwFormatStrType,
  1515.     IN void     *pFormatStruct,
  1516.     IN LPCSTR lpszStructType,
  1517.     IN const BYTE *pbEncoded,
  1518.     IN DWORD cbEncoded,
  1519.     OUT void *pbFormat,
  1520.     IN OUT DWORD *pcbFormat
  1521.     );
  1522.  
  1523. //+-------------------------------------------------------------------------
  1524. //  Encode / decode the specified data structure according to the certificate
  1525. //  encoding type.
  1526. //
  1527. //  See below for a list of the predefined data structures.
  1528. //--------------------------------------------------------------------------
  1529.  
  1530.  
  1531. WINCRYPT32API
  1532. BOOL
  1533. WINAPI
  1534. CryptEncodeObject(
  1535.     IN DWORD        dwCertEncodingType,
  1536.     IN LPCSTR       lpszStructType,
  1537.     IN const void   *pvStructInfo,
  1538.     OUT BYTE        *pbEncoded,
  1539.     IN OUT DWORD    *pcbEncoded
  1540.     );
  1541.  
  1542. WINCRYPT32API
  1543. BOOL
  1544. WINAPI
  1545. CryptDecodeObject(
  1546.     IN DWORD        dwCertEncodingType,
  1547.     IN LPCSTR       lpszStructType,
  1548.     IN const BYTE   *pbEncoded,
  1549.     IN DWORD        cbEncoded,
  1550.     IN DWORD        dwFlags,
  1551.     OUT void        *pvStructInfo,
  1552.     IN OUT DWORD    *pcbStructInfo
  1553.     );
  1554.  
  1555. // When the following flag is set the nocopy optimization is enabled.
  1556. // This optimization where appropriate, updates the pvStructInfo fields
  1557. // to point to content residing within pbEncoded instead of making a copy
  1558. // of and appending to pvStructInfo.
  1559. //
  1560. // Note, when set, pbEncoded can't be freed until pvStructInfo is freed.
  1561. #define CRYPT_DECODE_NOCOPY_FLAG            0x1
  1562.  
  1563. //+-------------------------------------------------------------------------
  1564. //  Predefined X509 certificate data structures that can be encoded / decoded.
  1565. //--------------------------------------------------------------------------
  1566. #define CRYPT_ENCODE_DECODE_NONE            0
  1567. #define X509_CERT                           ((LPCSTR) 1)
  1568. #define X509_CERT_TO_BE_SIGNED              ((LPCSTR) 2)
  1569. #define X509_CERT_CRL_TO_BE_SIGNED          ((LPCSTR) 3)
  1570. #define X509_CERT_REQUEST_TO_BE_SIGNED      ((LPCSTR) 4)
  1571. #define X509_EXTENSIONS                     ((LPCSTR) 5)
  1572. #define X509_NAME_VALUE                     ((LPCSTR) 6)
  1573. #define X509_NAME                           ((LPCSTR) 7)
  1574. #define X509_PUBLIC_KEY_INFO                ((LPCSTR) 8)
  1575.  
  1576. //+-------------------------------------------------------------------------
  1577. //  Predefined X509 certificate extension data structures that can be
  1578. //  encoded / decoded.
  1579. //--------------------------------------------------------------------------
  1580. #define X509_AUTHORITY_KEY_ID               ((LPCSTR) 9)
  1581. #define X509_KEY_ATTRIBUTES                 ((LPCSTR) 10)
  1582. #define X509_KEY_USAGE_RESTRICTION          ((LPCSTR) 11)
  1583. #define X509_ALTERNATE_NAME                 ((LPCSTR) 12)
  1584. #define X509_BASIC_CONSTRAINTS              ((LPCSTR) 13)
  1585. #define X509_KEY_USAGE                      ((LPCSTR) 14)
  1586. #define X509_BASIC_CONSTRAINTS2             ((LPCSTR) 15)
  1587. #define X509_CERT_POLICIES                  ((LPCSTR) 16)
  1588.  
  1589. //+-------------------------------------------------------------------------
  1590. //  Additional predefined data structures that can be encoded / decoded.
  1591. //--------------------------------------------------------------------------
  1592. #define PKCS_UTC_TIME                       ((LPCSTR) 17)
  1593. #define PKCS_TIME_REQUEST                   ((LPCSTR) 18)
  1594. #define RSA_CSP_PUBLICKEYBLOB               ((LPCSTR) 19)
  1595. #define X509_UNICODE_NAME                   ((LPCSTR) 20)
  1596.  
  1597. #define X509_KEYGEN_REQUEST_TO_BE_SIGNED    ((LPCSTR) 21)
  1598. #define PKCS_ATTRIBUTE                      ((LPCSTR) 22)
  1599. #define PKCS_CONTENT_INFO_SEQUENCE_OF_ANY   ((LPCSTR) 23)
  1600.  
  1601. //+-------------------------------------------------------------------------
  1602. //  Predefined primitive data structures that can be encoded / decoded.
  1603. //--------------------------------------------------------------------------
  1604. #define X509_UNICODE_NAME_VALUE             ((LPCSTR) 24)
  1605. #define X509_ANY_STRING                     X509_NAME_VALUE
  1606. #define X509_UNICODE_ANY_STRING             X509_UNICODE_NAME_VALUE
  1607. #define X509_OCTET_STRING                   ((LPCSTR) 25)
  1608. #define X509_BITS                           ((LPCSTR) 26)
  1609. #define X509_INTEGER                        ((LPCSTR) 27)
  1610. #define X509_MULTI_BYTE_INTEGER             ((LPCSTR) 28)
  1611. #define X509_ENUMERATED                     ((LPCSTR) 29)
  1612. #define X509_CHOICE_OF_TIME                 ((LPCSTR) 30)
  1613.  
  1614. //+-------------------------------------------------------------------------
  1615. //  More predefined X509 certificate extension data structures that can be
  1616. //  encoded / decoded.
  1617. //--------------------------------------------------------------------------
  1618. #define X509_AUTHORITY_KEY_ID2              ((LPCSTR) 31)
  1619. //#define X509_AUTHORITY_INFO_ACCESS          ((LPCSTR) 32)
  1620. #define X509_CRL_REASON_CODE                X509_ENUMERATED
  1621. #define PKCS_CONTENT_INFO                   ((LPCSTR) 33)
  1622. #define X509_SEQUENCE_OF_ANY                ((LPCSTR) 34)
  1623. #define X509_CRL_DIST_POINTS                ((LPCSTR) 35)
  1624. #define X509_ENHANCED_KEY_USAGE             ((LPCSTR) 36)
  1625. #define PKCS_CTL                            ((LPCSTR) 37)
  1626.  
  1627. #define X509_MULTI_BYTE_UINT                ((LPCSTR) 38)
  1628. #define X509_DSS_PUBLICKEY                  X509_MULTI_BYTE_UINT
  1629. #define X509_DSS_PARAMETERS                 ((LPCSTR) 39)
  1630. #define X509_DSS_SIGNATURE                  ((LPCSTR) 40)
  1631. #define PKCS_RC2_CBC_PARAMETERS             ((LPCSTR) 41)
  1632. #define PKCS_SMIME_CAPABILITIES             ((LPCSTR) 42)
  1633.  
  1634.  
  1635. //+-------------------------------------------------------------------------
  1636. //  Predefined PKCS #7 data structures that can be encoded / decoded.
  1637. //--------------------------------------------------------------------------
  1638. #define PKCS7_SIGNER_INFO                   ((LPCSTR) 500)
  1639.  
  1640. //+-------------------------------------------------------------------------
  1641. //  Predefined Software Publishing Credential (SPC)  data structures that
  1642. //  can be encoded / decoded.
  1643. //
  1644. //  Predefined values: 2000 .. 2999
  1645. //
  1646. //  See spc.h for value and data structure definitions.
  1647. //--------------------------------------------------------------------------
  1648.  
  1649. //+-------------------------------------------------------------------------
  1650. //  Extension Object Identifiers
  1651. //--------------------------------------------------------------------------
  1652. #define szOID_AUTHORITY_KEY_IDENTIFIER  "2.5.29.1"
  1653. #define szOID_KEY_ATTRIBUTES            "2.5.29.2"
  1654. #define szOID_KEY_USAGE_RESTRICTION     "2.5.29.4"
  1655. #define szOID_SUBJECT_ALT_NAME          "2.5.29.7"
  1656. #define szOID_ISSUER_ALT_NAME           "2.5.29.8"
  1657. #define szOID_BASIC_CONSTRAINTS         "2.5.29.10"
  1658. #define szOID_KEY_USAGE                 "2.5.29.15"
  1659. #define szOID_BASIC_CONSTRAINTS2        "2.5.29.19"
  1660. #define szOID_CERT_POLICIES             "2.5.29.32"
  1661.  
  1662. #define szOID_AUTHORITY_KEY_IDENTIFIER2 "2.5.29.35"
  1663. #define szOID_SUBJECT_KEY_IDENTIFIER    "2.5.29.14"
  1664. #define szOID_SUBJECT_ALT_NAME2         "2.5.29.17"
  1665. #define szOID_ISSUER_ALT_NAME2          "2.5.29.18"
  1666. #define szOID_CRL_REASON_CODE           "2.5.29.21"
  1667. #define szOID_CRL_DIST_POINTS           "2.5.29.31"
  1668. #define szOID_ENHANCED_KEY_USAGE        "2.5.29.37"
  1669.  
  1670.  
  1671. // Internet Public Key Infrastructure
  1672. #define szOID_PKIX                      "1.3.6.1.5.5.7"
  1673. #define szOID_AUTHORITY_INFO_ACCESS     "1.3.6.1.5.5.7.2"
  1674.  
  1675. // Microsoft extensions or attributes
  1676. #define szOID_CERT_EXTENSIONS           "1.3.6.1.4.1.311.2.1.14"
  1677. #define szOID_NEXT_UPDATE_LOCATION      "1.3.6.1.4.1.311.10.2"
  1678.  
  1679. //  Microsoft PKCS #7 ContentType Object Identifiers
  1680. #define szOID_CTL                       "1.3.6.1.4.1.311.10.1"
  1681.  
  1682. //+-------------------------------------------------------------------------
  1683. //  Extension Object Identifiers (currently not implemented)
  1684. //--------------------------------------------------------------------------
  1685. #define szOID_POLICY_MAPPINGS           "2.5.29.5"
  1686. #define szOID_SUBJECT_DIR_ATTRS         "2.5.29.9"
  1687.  
  1688. //+-------------------------------------------------------------------------
  1689. //  Enhanced Key Usage (Purpose) Object Identifiers
  1690. //--------------------------------------------------------------------------
  1691. #define szOID_PKIX_KP                   "1.3.6.1.5.5.7.3"
  1692.  
  1693. // Consistent key usage bits: DIGITAL_SIGNATURE, KEY_ENCIPHERMENT
  1694. // or KEY_AGREEMENT
  1695. #define szOID_PKIX_KP_SERVER_AUTH       "1.3.6.1.5.5.7.3.1"
  1696.  
  1697. // Consistent key usage bits: DIGITAL_SIGNATURE
  1698. #define szOID_PKIX_KP_CLIENT_AUTH       "1.3.6.1.5.5.7.3.2"
  1699.  
  1700. // Consistent key usage bits: DIGITAL_SIGNATURE
  1701. #define szOID_PKIX_KP_CODE_SIGNING      "1.3.6.1.5.5.7.3.3"
  1702.  
  1703. // Consistent key usage bits: DIGITAL_SIGNATURE, NON_REPUDIATION and/or
  1704. // (KEY_ENCIPHERMENT or KEY_AGREEMENT)
  1705. #define szOID_PKIX_KP_EMAIL_PROTECTION  "1.3.6.1.5.5.7.3.4"
  1706.  
  1707. //+-------------------------------------------------------------------------
  1708. //  Microsoft Enhanced Key Usage (Purpose) Object Identifiers
  1709. //+-------------------------------------------------------------------------
  1710.  
  1711. //  Signer of CTLs
  1712. #define szOID_KP_CTL_USAGE_SIGNING      "1.3.6.1.4.1.311.10.3.1"
  1713.  
  1714. //  Signer of TimeStamps
  1715. #define szOID_KP_TIME_STAMP_SIGNING         "1.3.6.1.4.1.311.10.3.2"
  1716.  
  1717. //+-------------------------------------------------------------------------
  1718. //  Microsoft Attribute Object Identifiers
  1719. //+-------------------------------------------------------------------------
  1720. #define szOID_YESNO_TRUST_ATTR          "1.3.6.1.4.1.311.10.4.1"
  1721.  
  1722. //+-------------------------------------------------------------------------
  1723. //  X509_CERT
  1724. //
  1725. //  The "to be signed" encoded content plus its signature. The ToBeSigned
  1726. //  content is the CryptEncodeObject() output for one of the following:
  1727. //  X509_CERT_TO_BE_SIGNED, X509_CERT_CRL_TO_BE_SIGNED or
  1728. //  X509_CERT_REQUEST_TO_BE_SIGNED.
  1729. //
  1730. //  pvStructInfo points to CERT_SIGNED_CONTENT_INFO.
  1731. //--------------------------------------------------------------------------
  1732.  
  1733. //+-------------------------------------------------------------------------
  1734. //  X509_CERT_TO_BE_SIGNED
  1735. //
  1736. //  pvStructInfo points to CERT_INFO.
  1737. //
  1738. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1739. //  signature (output of a X509_CERT CryptEncodeObject()).
  1740. //
  1741. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1742. //--------------------------------------------------------------------------
  1743.  
  1744. //+-------------------------------------------------------------------------
  1745. //  X509_CERT_CRL_TO_BE_SIGNED
  1746. //
  1747. //  pvStructInfo points to CRL_INFO.
  1748. //
  1749. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1750. //  signature (output of a X509_CERT CryptEncodeObject()).
  1751. //
  1752. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1753. //--------------------------------------------------------------------------
  1754.  
  1755. //+-------------------------------------------------------------------------
  1756. //  X509_CERT_REQUEST_TO_BE_SIGNED
  1757. //
  1758. //  pvStructInfo points to CERT_REQUEST_INFO.
  1759. //
  1760. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  1761. //  signature (output of a X509_CERT CryptEncodeObject()).
  1762. //
  1763. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  1764. //--------------------------------------------------------------------------
  1765.  
  1766. //+-------------------------------------------------------------------------
  1767. //  X509_EXTENSIONS
  1768. //  szOID_CERT_EXTENSIONS
  1769. //
  1770. //  pvStructInfo points to following CERT_EXTENSIONS.
  1771. //--------------------------------------------------------------------------
  1772. typedef struct _CERT_EXTENSIONS {
  1773.     DWORD           cExtension;
  1774.     PCERT_EXTENSION rgExtension;
  1775. } CERT_EXTENSIONS, *PCERT_EXTENSIONS;
  1776.  
  1777. //+-------------------------------------------------------------------------
  1778. //  X509_NAME_VALUE
  1779. //  X509_ANY_STRING
  1780. //
  1781. //  pvStructInfo points to CERT_NAME_VALUE.
  1782. //--------------------------------------------------------------------------
  1783.  
  1784. //+-------------------------------------------------------------------------
  1785. //  X509_UNICODE_NAME_VALUE
  1786. //  X509_UNICODE_ANY_STRING
  1787. //
  1788. //  pvStructInfo points to CERT_NAME_VALUE.
  1789. //
  1790. //  The name values are unicode strings.
  1791. //
  1792. //  For CryptEncodeObject:
  1793. //    Value.pbData points to the unicode string.
  1794. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  1795. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  1796. //    is twice the character count.
  1797. //
  1798. //    If the unicode string contains an invalid character for the specified
  1799. //    dwValueType, then, *pcbEncoded is updated with the unicode character
  1800. //    index of the first invalid character. LastError is set to:
  1801. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1802. //    CRYPT_E_INVALID_IA5_STRING.
  1803. //
  1804. //    The unicode string is converted before being encoded according to
  1805. //    the specified dwValueType. If dwValueType is set to 0, LastError
  1806. //    is set to E_INVALIDARG.
  1807. //
  1808. //    If the dwValueType isn't one of the character strings (its a
  1809. //    CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING), then, CryptEncodeObject
  1810. //    will return FALSE with LastError set to CRYPT_E_NOT_CHAR_STRING.
  1811. //
  1812. //  For CryptDecodeObject:
  1813. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  1814. //    contains the byte count of the unicode string excluding the NULL
  1815. //    terminator. dwValueType contains the type used in the encoded object.
  1816. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1817. //    converted to the unicode string according to the dwValueType.
  1818. //
  1819. //    If the encoded object isn't one of the character string types, then,
  1820. //    CryptDecodeObject will return FALSE with LastError set to
  1821. //    CRYPT_E_NOT_CHAR_STRING. For a non character string, decode using
  1822. //    X509_NAME_VALUE or X509_ANY_STRING.
  1823. //--------------------------------------------------------------------------
  1824.  
  1825. //+-------------------------------------------------------------------------
  1826. //  X509_NAME
  1827. //
  1828. //  pvStructInfo points to CERT_NAME_INFO.
  1829. //--------------------------------------------------------------------------
  1830.  
  1831. //+-------------------------------------------------------------------------
  1832. //  X509_UNICODE_NAME
  1833. //
  1834. //  pvStructInfo points to CERT_NAME_INFO.
  1835. //
  1836. //  The RDN attribute values are unicode strings except for the dwValueTypes of
  1837. //  CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING. These dwValueTypes are
  1838. //  the same as for a X509_NAME. Their values aren't converted to/from unicode.
  1839. //
  1840. //  For CryptEncodeObject:
  1841. //    Value.pbData points to the unicode string.
  1842. //    If Value.cbData = 0, then, the unicode string is NULL terminated.
  1843. //    Otherwise, Value.cbData is the unicode string byte count. The byte count
  1844. //    is twice the character count.
  1845. //
  1846. //    If dwValueType = 0 (CERT_RDN_ANY_TYPE), the pszObjId is used to find
  1847. //    an acceptable dwValueType. If the unicode string contains an
  1848. //    invalid character for the found or specified dwValueType, then,
  1849. //    *pcbEncoded is updated with the error location of the invalid character.
  1850. //    See below for details. LastError is set to:
  1851. //    CRYPT_E_INVALID_NUMERIC_STRING, CRYPT_E_INVALID_PRINTABLE_STRING or
  1852. //    CRYPT_E_INVALID_IA5_STRING.
  1853. //
  1854. //    The unicode string is converted before being encoded according to
  1855. //    the specified or ObjId matching dwValueType.
  1856. //
  1857. //  For CryptDecodeObject:
  1858. //    Value.pbData points to a NULL terminated unicode string. Value.cbData
  1859. //    contains the byte count of the unicode string excluding the NULL
  1860. //    terminator. dwValueType contains the type used in the encoded object.
  1861. //    Its not forced to CERT_RDN_UNICODE_STRING. The encoded value is
  1862. //    converted to the unicode string according to the dwValueType.
  1863. //
  1864. //    If the dwValueType of the encoded value isn't a character string
  1865. //    type, then, it isn't converted to UNICODE. Use the
  1866. //    IS_CERT_RDN_CHAR_STRING() macro on the dwValueType to check
  1867. //    that Value.pbData points to a converted unicode string.
  1868. //--------------------------------------------------------------------------
  1869.  
  1870. //+-------------------------------------------------------------------------
  1871. //  Unicode Name Value Error Location Definitions
  1872. //
  1873. //  Error location is returned in *pcbEncoded by
  1874. //  CryptEncodeObject(X509_UNICODE_NAME)
  1875. //
  1876. //  Error location consists of:
  1877. //    RDN_INDEX     - 10 bits << 22
  1878. //    ATTR_INDEX    - 6 bits << 16
  1879. //    VALUE_INDEX   - 16 bits (unicode character index)
  1880. //--------------------------------------------------------------------------
  1881. #define CERT_UNICODE_RDN_ERR_INDEX_MASK     0x3FF
  1882. #define CERT_UNICODE_RDN_ERR_INDEX_SHIFT    22
  1883. #define CERT_UNICODE_ATTR_ERR_INDEX_MASK    0x003F
  1884. #define CERT_UNICODE_ATTR_ERR_INDEX_SHIFT   16
  1885. #define CERT_UNICODE_VALUE_ERR_INDEX_MASK   0x0000FFFF
  1886. #define CERT_UNICODE_VALUE_ERR_INDEX_SHIFT  0
  1887.  
  1888. #define GET_CERT_UNICODE_RDN_ERR_INDEX(X)   \
  1889.     ((X >> CERT_UNICODE_RDN_ERR_INDEX_SHIFT) & CERT_UNICODE_RDN_ERR_INDEX_MASK)
  1890. #define GET_CERT_UNICODE_ATTR_ERR_INDEX(X)  \
  1891.     ((X >> CERT_UNICODE_ATTR_ERR_INDEX_SHIFT) & CERT_UNICODE_ATTR_ERR_INDEX_MASK)
  1892. #define GET_CERT_UNICODE_VALUE_ERR_INDEX(X) \
  1893.     (X & CERT_UNICODE_VALUE_ERR_INDEX_MASK)
  1894.  
  1895. //+-------------------------------------------------------------------------
  1896. //  X509_PUBLIC_KEY_INFO
  1897. //
  1898. //  pvStructInfo points to CERT_PUBLIC_KEY_INFO.
  1899. //--------------------------------------------------------------------------
  1900.  
  1901.  
  1902. //+-------------------------------------------------------------------------
  1903. //  X509_AUTHORITY_KEY_ID
  1904. //  szOID_AUTHORITY_KEY_IDENTIFIER
  1905. //
  1906. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID_INFO.
  1907. //--------------------------------------------------------------------------
  1908. typedef struct _CERT_AUTHORITY_KEY_ID_INFO {
  1909.     CRYPT_DATA_BLOB     KeyId;
  1910.     CERT_NAME_BLOB      CertIssuer;
  1911.     CRYPT_INTEGER_BLOB  CertSerialNumber;
  1912. } CERT_AUTHORITY_KEY_ID_INFO, *PCERT_AUTHORITY_KEY_ID_INFO;
  1913.  
  1914. //+-------------------------------------------------------------------------
  1915. //  X509_KEY_ATTRIBUTES
  1916. //  szOID_KEY_ATTRIBUTES
  1917. //
  1918. //  pvStructInfo points to following CERT_KEY_ATTRIBUTES_INFO.
  1919. //--------------------------------------------------------------------------
  1920. typedef struct _CERT_PRIVATE_KEY_VALIDITY {
  1921.     FILETIME                NotBefore;
  1922.     FILETIME                NotAfter;
  1923. } CERT_PRIVATE_KEY_VALIDITY, *PCERT_PRIVATE_KEY_VALIDITY;
  1924.  
  1925. typedef struct _CERT_KEY_ATTRIBUTES_INFO {
  1926.     CRYPT_DATA_BLOB             KeyId;
  1927.     CRYPT_BIT_BLOB              IntendedKeyUsage;
  1928.     PCERT_PRIVATE_KEY_VALIDITY  pPrivateKeyUsagePeriod;     // OPTIONAL
  1929. } CERT_KEY_ATTRIBUTES_INFO, *PCERT_KEY_ATTRIBUTES_INFO;
  1930.  
  1931. #define CERT_DIGITAL_SIGNATURE_KEY_USAGE     0x80
  1932. #define CERT_NON_REPUDIATION_KEY_USAGE       0x40
  1933. #define CERT_KEY_ENCIPHERMENT_KEY_USAGE      0x20
  1934. #define CERT_DATA_ENCIPHERMENT_KEY_USAGE     0x10
  1935. #define CERT_KEY_AGREEMENT_KEY_USAGE         0x08
  1936. #define CERT_KEY_CERT_SIGN_KEY_USAGE         0x04
  1937. #define CERT_OFFLINE_CRL_SIGN_KEY_USAGE      0x02
  1938.  
  1939. #define CERT_CRL_SIGN_KEY_USAGE              0x02
  1940.  
  1941. //+-------------------------------------------------------------------------
  1942. //  X509_KEY_USAGE_RESTRICTION
  1943. //  szOID_KEY_USAGE_RESTRICTION
  1944. //
  1945. //  pvStructInfo points to following CERT_KEY_USAGE_RESTRICTION_INFO.
  1946. //--------------------------------------------------------------------------
  1947. typedef struct _CERT_POLICY_ID {
  1948.     DWORD                   cCertPolicyElementId;
  1949.     LPSTR                   *rgpszCertPolicyElementId;  // pszObjId
  1950. } CERT_POLICY_ID, *PCERT_POLICY_ID;
  1951.  
  1952. typedef struct _CERT_KEY_USAGE_RESTRICTION_INFO {
  1953.     DWORD                   cCertPolicyId;
  1954.     PCERT_POLICY_ID         rgCertPolicyId;
  1955.     CRYPT_BIT_BLOB          RestrictedKeyUsage;
  1956. } CERT_KEY_USAGE_RESTRICTION_INFO, *PCERT_KEY_USAGE_RESTRICTION_INFO;
  1957.  
  1958. // See CERT_KEY_ATTRIBUTES_INFO for definition of the RestrictedKeyUsage bits
  1959.  
  1960. //+-------------------------------------------------------------------------
  1961. //  X509_ALTERNATE_NAME
  1962. //  szOID_SUBJECT_ALT_NAME
  1963. //  szOID_ISSUER_ALT_NAME
  1964. //  szOID_SUBJECT_ALT_NAME2
  1965. //  szOID_ISSUER_ALT_NAME2
  1966. //
  1967. //  pvStructInfo points to following CERT_ALT_NAME_INFO.
  1968. //--------------------------------------------------------------------------
  1969.  
  1970. typedef struct _CERT_ALT_NAME_ENTRY {
  1971.     DWORD   dwAltNameChoice;
  1972.     union {
  1973.         // Not implemented          OtherName;          // 1
  1974.         LPWSTR                      pwszRfc822Name;     // 2  (encoded IA5)
  1975.         LPWSTR                      pwszDNSName;        // 3  (encoded IA5)
  1976.         // Not implemented          x400Address;        // 4
  1977.         CERT_NAME_BLOB              DirectoryName;      // 5
  1978.         // Not implemented          pEdiPartyName;      // 6
  1979.         LPWSTR                      pwszURL;            // 7  (encoded IA5)
  1980.         CRYPT_DATA_BLOB             IPAddress;          // 8  (Octet String)
  1981.         LPSTR                       pszRegisteredID;    // 9  (Object Identifer)
  1982.     };
  1983. } CERT_ALT_NAME_ENTRY, *PCERT_ALT_NAME_ENTRY;
  1984.  
  1985. #define CERT_ALT_NAME_OTHER_NAME         1
  1986. #define CERT_ALT_NAME_RFC822_NAME        2
  1987. #define CERT_ALT_NAME_DNS_NAME           3
  1988. #define CERT_ALT_NAME_X400_ADDRESS       4
  1989. #define CERT_ALT_NAME_DIRECTORY_NAME     5
  1990. #define CERT_ALT_NAME_EDI_PARTY_NAME     6
  1991. #define CERT_ALT_NAME_URL                7
  1992. #define CERT_ALT_NAME_IP_ADDRESS         8
  1993. #define CERT_ALT_NAME_REGISTERED_ID      9
  1994.  
  1995.  
  1996. typedef struct _CERT_ALT_NAME_INFO {
  1997.     DWORD                   cAltEntry;
  1998.     PCERT_ALT_NAME_ENTRY    rgAltEntry;
  1999. } CERT_ALT_NAME_INFO, *PCERT_ALT_NAME_INFO;
  2000.  
  2001. //+-------------------------------------------------------------------------
  2002. //  Alternate name IA5 Error Location Definitions for
  2003. //  CRYPT_E_INVALID_IA5_STRING.
  2004. //
  2005. //  Error location is returned in *pcbEncoded by
  2006. //  CryptEncodeObject(X509_ALTERNATE_NAME)
  2007. //
  2008. //  Error location consists of:
  2009. //    ENTRY_INDEX   - 8 bits << 16
  2010. //    VALUE_INDEX   - 16 bits (unicode character index)
  2011. //--------------------------------------------------------------------------
  2012. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK  0xFF
  2013. #define CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT 16
  2014. #define CERT_ALT_NAME_VALUE_ERR_INDEX_MASK  0x0000FFFF
  2015. #define CERT_ALT_NAME_VALUE_ERR_INDEX_SHIFT 0
  2016.  
  2017. #define GET_CERT_ALT_NAME_ENTRY_ERR_INDEX(X)   \
  2018.     ((X >> CERT_ALT_NAME_ENTRY_ERR_INDEX_SHIFT) & \
  2019.     CERT_ALT_NAME_ENTRY_ERR_INDEX_MASK)
  2020. #define GET_CERT_ALT_NAME_VALUE_ERR_INDEX(X) \
  2021.     (X & CERT_ALT_NAME_VALUE_ERR_INDEX_MASK)
  2022.  
  2023.  
  2024. //+-------------------------------------------------------------------------
  2025. //  X509_BASIC_CONSTRAINTS
  2026. //  szOID_BASIC_CONSTRAINTS
  2027. //
  2028. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS_INFO.
  2029. //--------------------------------------------------------------------------
  2030. typedef struct _CERT_BASIC_CONSTRAINTS_INFO {
  2031.     CRYPT_BIT_BLOB          SubjectType;
  2032.     BOOL                    fPathLenConstraint;
  2033.     DWORD                   dwPathLenConstraint;
  2034.     DWORD                   cSubtreesConstraint;
  2035.     CERT_NAME_BLOB          *rgSubtreesConstraint;
  2036. } CERT_BASIC_CONSTRAINTS_INFO, *PCERT_BASIC_CONSTRAINTS_INFO;
  2037.  
  2038. #define CERT_CA_SUBJECT_FLAG         0x80
  2039. #define CERT_END_ENTITY_SUBJECT_FLAG 0x40
  2040.  
  2041. //+-------------------------------------------------------------------------
  2042. //  X509_BASIC_CONSTRAINTS2
  2043. //  szOID_BASIC_CONSTRAINTS2
  2044. //
  2045. //  pvStructInfo points to following CERT_BASIC_CONSTRAINTS2_INFO.
  2046. //--------------------------------------------------------------------------
  2047. typedef struct _CERT_BASIC_CONSTRAINTS2_INFO {
  2048.     BOOL                    fCA;
  2049.     BOOL                    fPathLenConstraint;
  2050.     DWORD                   dwPathLenConstraint;
  2051. } CERT_BASIC_CONSTRAINTS2_INFO, *PCERT_BASIC_CONSTRAINTS2_INFO;
  2052.  
  2053. //+-------------------------------------------------------------------------
  2054. //  X509_KEY_USAGE
  2055. //  szOID_KEY_USAGE
  2056. //
  2057. //  pvStructInfo points to a CRYPT_BIT_BLOB. Has same bit definitions as
  2058. //  CERT_KEY_ATTRIBUTES_INFO's IntendedKeyUsage.
  2059. //--------------------------------------------------------------------------
  2060.  
  2061. //+-------------------------------------------------------------------------
  2062. //  X509_CERT_POLICIES
  2063. //  szOID_CERT_POLICIES
  2064. //
  2065. //  pvStructInfo points to following CERT_POLICIES_INFO.
  2066. //--------------------------------------------------------------------------
  2067. typedef struct _CERT_POLICY_QUALIFIER_INFO {
  2068.     LPSTR                       pszPolicyQualifierId;   // pszObjId
  2069.     CRYPT_OBJID_BLOB            Qualifier;              // optional
  2070. } CERT_POLICY_QUALIFIER_INFO, *PCERT_POLICY_QUALIFIER_INFO;
  2071.  
  2072. typedef struct _CERT_POLICY_INFO {
  2073.     LPSTR                       pszPolicyIdentifier;    // pszObjId
  2074.     DWORD                       cPolicyQualifier;       // optional
  2075.     CERT_POLICY_QUALIFIER_INFO  *rgPolicyQualifier;
  2076. } CERT_POLICY_INFO, *PCERT_POLICY_INFO;
  2077.  
  2078. typedef struct _CERT_POLICIES_INFO {
  2079.     DWORD                       cPolicyInfo;
  2080.     CERT_POLICY_INFO            *rgPolicyInfo;
  2081. } CERT_POLICIES_INFO, *PCERT_POLICIES_INFO;
  2082.  
  2083. //+-------------------------------------------------------------------------
  2084. //  RSA_CSP_PUBLICKEYBLOB
  2085. //
  2086. //  pvStructInfo points to a PUBLICKEYSTRUC immediately followed by a
  2087. //  RSAPUBKEY and the modulus bytes.
  2088. //
  2089. //  CryptExportKey outputs the above StructInfo for a dwBlobType of
  2090. //  PUBLICKEYBLOB. CryptImportKey expects the above StructInfo when
  2091. //  importing a public key.
  2092. //
  2093. //  For dwCertEncodingType = X509_ASN_ENCODING, the RSA_CSP_PUBLICKEYBLOB is
  2094. //  encoded as a PKCS #1 RSAPublicKey consisting of a SEQUENCE of a
  2095. //  modulus INTEGER and a publicExponent INTEGER. The modulus is encoded
  2096. //  as being a unsigned integer. When decoded, if the modulus was encoded
  2097. //  as unsigned integer with a leading 0 byte, the 0 byte is removed before
  2098. //  converting to the CSP modulus bytes.
  2099. //
  2100. //  For decode, the aiKeyAlg field of PUBLICKEYSTRUC is always set to
  2101. //  CALG_RSA_KEYX.
  2102. //--------------------------------------------------------------------------
  2103.  
  2104. //+-------------------------------------------------------------------------
  2105. //  X509_KEYGEN_REQUEST_TO_BE_SIGNED
  2106. //
  2107. //  pvStructInfo points to CERT_KEYGEN_REQUEST_INFO.
  2108. //
  2109. //  For CryptDecodeObject(), the pbEncoded is the "to be signed" plus its
  2110. //  signature (output of a X509_CERT CryptEncodeObject()).
  2111. //
  2112. //  For CryptEncodeObject(), the pbEncoded is just the "to be signed".
  2113. //--------------------------------------------------------------------------
  2114.  
  2115. //+-------------------------------------------------------------------------
  2116. //  PKCS_ATTRIBUTE data structure
  2117. //
  2118. //  pvStructInfo points to a CRYPT_ATTRIBUTE.
  2119. //--------------------------------------------------------------------------
  2120.  
  2121. //+-------------------------------------------------------------------------
  2122. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY data structure
  2123. //
  2124. //  pvStructInfo points to following CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY.
  2125. //
  2126. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure wrapping
  2127. //  a sequence of ANY. The value of the contentType field is pszObjId,
  2128. //  while the content field is the following structure:
  2129. //      SequenceOfAny ::= SEQUENCE OF ANY
  2130. //
  2131. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2132. //--------------------------------------------------------------------------
  2133. typedef struct _CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY {
  2134.     LPSTR               pszObjId;
  2135.     DWORD               cValue;
  2136.     PCRYPT_DER_BLOB     rgValue;
  2137. } CRYPT_CONTENT_INFO_SEQUENCE_OF_ANY, *PCRYPT_CONTENT_INFO_SEQUENCE_OF_ANY;
  2138.  
  2139. //+-------------------------------------------------------------------------
  2140. //  PKCS_CONTENT_INFO data structure
  2141. //
  2142. //  pvStructInfo points to following CRYPT_CONTENT_INFO.
  2143. //
  2144. //  For X509_ASN_ENCODING: encoded as a PKCS#7 ContentInfo structure.
  2145. //  The CRYPT_DER_BLOB points to the already encoded ANY content.
  2146. //--------------------------------------------------------------------------
  2147. typedef struct _CRYPT_CONTENT_INFO {
  2148.     LPSTR               pszObjId;
  2149.     CRYPT_DER_BLOB      Content;
  2150. } CRYPT_CONTENT_INFO, *PCRYPT_CONTENT_INFO;
  2151.  
  2152.  
  2153. //+-------------------------------------------------------------------------
  2154. //  X509_OCTET_STRING data structure
  2155. //
  2156. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  2157. //--------------------------------------------------------------------------
  2158.  
  2159. //+-------------------------------------------------------------------------
  2160. //  X509_BITS data structure
  2161. //
  2162. //  pvStructInfo points to a CRYPT_BIT_BLOB.
  2163. //--------------------------------------------------------------------------
  2164.  
  2165. //+-------------------------------------------------------------------------
  2166. //  X509_INTEGER data structure
  2167. //
  2168. //  pvStructInfo points to an int.
  2169. //--------------------------------------------------------------------------
  2170.  
  2171. //+-------------------------------------------------------------------------
  2172. //  X509_MULTI_BYTE_INTEGER data structure
  2173. //
  2174. //  pvStructInfo points to a CRYPT_INTEGER_BLOB.
  2175. //--------------------------------------------------------------------------
  2176.  
  2177. //+-------------------------------------------------------------------------
  2178. //  X509_ENUMERATED data structure
  2179. //
  2180. //  pvStructInfo points to an int containing the enumerated value
  2181. //--------------------------------------------------------------------------
  2182.  
  2183. //+-------------------------------------------------------------------------
  2184. //  X509_CHOICE_OF_TIME data structure
  2185. //
  2186. //  pvStructInfo points to a FILETIME.
  2187. //--------------------------------------------------------------------------
  2188.  
  2189. //+-------------------------------------------------------------------------
  2190. //  X509_SEQUENCE_OF_ANY data structure
  2191. //
  2192. //  pvStructInfo points to following CRYPT_SEQUENCE_OF_ANY.
  2193. //
  2194. //  The CRYPT_DER_BLOBs point to the already encoded ANY content.
  2195. //--------------------------------------------------------------------------
  2196. typedef struct _CRYPT_SEQUENCE_OF_ANY {
  2197.     DWORD               cValue;
  2198.     PCRYPT_DER_BLOB     rgValue;
  2199. } CRYPT_SEQUENCE_OF_ANY, *PCRYPT_SEQUENCE_OF_ANY;
  2200.  
  2201.  
  2202. //+-------------------------------------------------------------------------
  2203. //  X509_AUTHORITY_KEY_ID2
  2204. //  szOID_AUTHORITY_KEY_IDENTIFIER2
  2205. //
  2206. //  pvStructInfo points to following CERT_AUTHORITY_KEY_ID2_INFO.
  2207. //
  2208. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2209. //  *pcbEncoded by CryptEncodeObject(X509_AUTHORITY_KEY_ID2)
  2210. //
  2211. //  See X509_ALTERNATE_NAME for error location defines.
  2212. //--------------------------------------------------------------------------
  2213. typedef struct _CERT_AUTHORITY_KEY_ID2_INFO {
  2214.     CRYPT_DATA_BLOB     KeyId;
  2215.     CERT_ALT_NAME_INFO  AuthorityCertIssuer;    // Optional, set cAltEntry
  2216.                                                 // to 0 to omit.
  2217.     CRYPT_INTEGER_BLOB  AuthorityCertSerialNumber;
  2218. } CERT_AUTHORITY_KEY_ID2_INFO, *PCERT_AUTHORITY_KEY_ID2_INFO;
  2219.  
  2220. //+-------------------------------------------------------------------------
  2221. //  szOID_SUBJECT_KEY_IDENTIFIER
  2222. //
  2223. //  pvStructInfo points to a CRYPT_DATA_BLOB.
  2224. //--------------------------------------------------------------------------
  2225.  
  2226.  
  2227. //+-------------------------------------------------------------------------
  2228. //  X509_CRL_REASON_CODE
  2229. //  szOID_CRL_REASON_CODE
  2230. //
  2231. //  pvStructInfo points to an int which can be set to one of the following
  2232. //  enumerated values:
  2233. //--------------------------------------------------------------------------
  2234. #define CRL_REASON_UNSPECIFIED              0
  2235. #define CRL_REASON_KEY_COMPROMISE           1
  2236. #define CRL_REASON_CA_COMPROMISE            2
  2237. #define CRL_REASON_AFFILIATION_CHANGED      3
  2238. #define CRL_REASON_SUPERSEDED               4
  2239. #define CRL_REASON_CESSATION_OF_OPERATION   5
  2240. #define CRL_REASON_CERTIFICATE_HOLD         6
  2241. #define CRL_REASON_REMOVE_FROM_CRL          8
  2242.  
  2243.  
  2244. //+-------------------------------------------------------------------------
  2245. //  X509_CRL_DIST_POINTS
  2246. //  szOID_CRL_DIST_POINTS
  2247. //
  2248. //  pvStructInfo points to following CRL_DIST_POINTS_INFO.
  2249. //
  2250. //  For CRYPT_E_INVALID_IA5_STRING, the error location is returned in
  2251. //  *pcbEncoded by CryptEncodeObject(X509_CRL_DIST_POINTS)
  2252. //
  2253. //  Error location consists of:
  2254. //    CRL_ISSUER_BIT    - 1 bit  << 31 (0 for FullName, 1 for CRLIssuer)
  2255. //    POINT_INDEX       - 7 bits << 24
  2256. //    ENTRY_INDEX       - 8 bits << 16
  2257. //    VALUE_INDEX       - 16 bits (unicode character index)
  2258. //
  2259. //  See X509_ALTERNATE_NAME for ENTRY_INDEX and VALUE_INDEX error location
  2260. //  defines.
  2261. //--------------------------------------------------------------------------
  2262. typedef struct _CRL_DIST_POINT_NAME {
  2263.     DWORD   dwDistPointNameChoice;
  2264.     union {
  2265.         CERT_ALT_NAME_INFO      FullName;       // 1
  2266.         // Not implemented      IssuerRDN;      // 2
  2267.     };
  2268. } CRL_DIST_POINT_NAME, *PCRL_DIST_POINT_NAME;
  2269.  
  2270. #define CRL_DIST_POINT_NO_NAME          0
  2271. #define CRL_DIST_POINT_FULL_NAME        1
  2272. #define CRL_DIST_POINT_ISSUER_RDN_NAME  2
  2273.  
  2274. typedef struct _CRL_DIST_POINT {
  2275.     CRL_DIST_POINT_NAME     DistPointName;      // OPTIONAL
  2276.     CRYPT_BIT_BLOB          ReasonFlags;        // OPTIONAL
  2277.     CERT_ALT_NAME_INFO      CRLIssuer;          // OPTIONAL
  2278. } CRL_DIST_POINT, *PCRL_DIST_POINT;
  2279.  
  2280. #define CRL_REASON_UNUSED_FLAG                  0x80
  2281. #define CRL_REASON_KEY_COMPROMISE_FLAG          0x40
  2282. #define CRL_REASON_CA_COMPROMISE_FLAG           0x20
  2283. #define CRL_REASON_AFFILIATION_CHANGED_FLAG     0x10
  2284. #define CRL_REASON_SUPERSEDED_FLAG              0x08
  2285. #define CRL_REASON_CESSATION_OF_OPERATION_FLAG  0x04
  2286. #define CRL_REASON_CERTIFICATE_HOLD_FLAG        0x02
  2287.  
  2288. typedef struct _CRL_DIST_POINTS_INFO {
  2289.     DWORD                   cDistPoint;
  2290.     PCRL_DIST_POINT         rgDistPoint;
  2291. } CRL_DIST_POINTS_INFO, *PCRL_DIST_POINTS_INFO;
  2292.  
  2293. #define CRL_DIST_POINT_ERR_INDEX_MASK          0x7F
  2294. #define CRL_DIST_POINT_ERR_INDEX_SHIFT         24
  2295. #define GET_CRL_DIST_POINT_ERR_INDEX(X)   \
  2296.     ((X >> CRL_DIST_POINT_ERR_INDEX_SHIFT) & CRL_DIST_POINT_ERR_INDEX_MASK)
  2297.  
  2298. #define CRL_DIST_POINT_ERR_CRL_ISSUER_BIT      0x80000000L
  2299. #define IS_CRL_DIST_POINT_ERR_CRL_ISSUER(X)   \
  2300.     (0 != (X & CRL_DIST_POINT_ERR_CRL_ISSUER_BIT))
  2301.  
  2302.  
  2303. //+-------------------------------------------------------------------------
  2304. //  X509_ENHANCED_KEY_USAGE
  2305. //  szOID_ENHANCED_KEY_USAGE
  2306. //
  2307. //  pvStructInfo points to a CERT_ENHKEY_USAGE, CTL_USAGE.
  2308. //--------------------------------------------------------------------------
  2309.  
  2310. //+-------------------------------------------------------------------------
  2311. //  szOID_NEXT_UPDATE_LOCATION
  2312. //
  2313. //  pvStructInfo points to a CERT_ALT_NAME_INFO.
  2314. //--------------------------------------------------------------------------
  2315.  
  2316. //+-------------------------------------------------------------------------
  2317. //  PKCS_CTL
  2318. //  szOID_CTL
  2319. //
  2320. //  pvStructInfo points to a CTL_INFO.
  2321. //--------------------------------------------------------------------------
  2322.  
  2323. //+-------------------------------------------------------------------------
  2324. //  X509_MULTI_BYTE_UINT
  2325. //
  2326. //  pvStructInfo points to a CRYPT_UINT_BLOB. Before encoding, inserts a
  2327. //  leading 0x00. After decoding, removes a leading 0x00.
  2328. //--------------------------------------------------------------------------
  2329.  
  2330. //+-------------------------------------------------------------------------
  2331. //  X509_DSS_PUBLICKEY
  2332. //
  2333. //  pvStructInfo points to a CRYPT_UINT_BLOB.
  2334. //--------------------------------------------------------------------------
  2335.  
  2336. //+-------------------------------------------------------------------------
  2337. //  X509_DSS_PARAMETERS
  2338. //
  2339. //  pvStructInfo points to following CERT_DSS_PARAMETERS data structure.
  2340. //--------------------------------------------------------------------------
  2341. typedef struct _CERT_DSS_PARAMETERS {
  2342.     CRYPT_UINT_BLOB     p;
  2343.     CRYPT_UINT_BLOB     q;
  2344.     CRYPT_UINT_BLOB     g;
  2345. } CERT_DSS_PARAMETERS, *PCERT_DSS_PARAMETERS;
  2346.  
  2347. //+-------------------------------------------------------------------------
  2348. //  X509_DSS_SIGNATURE
  2349. //
  2350. //  pvStructInfo is a BYTE rgbSignature[CERT_DSS_SIGNATURE_LEN]. The
  2351. //  bytes are ordered as output by the DSS CSP's CryptSignHash().
  2352. //--------------------------------------------------------------------------
  2353. #define CERT_DSS_R_LEN          20
  2354. #define CERT_DSS_S_LEN          20
  2355. #define CERT_DSS_SIGNATURE_LEN  (CERT_DSS_R_LEN + CERT_DSS_S_LEN)
  2356.  
  2357. // Sequence of 2 unsigned integers (the extra +1 is for a potential leading
  2358. // 0x00 to make the integer unsigned)
  2359. #define CERT_MAX_ASN_ENCODED_DSS_SIGNATURE_LEN  (2 + 2*(2 + 20 +1))
  2360.  
  2361.  
  2362. //+-------------------------------------------------------------------------
  2363. //  PKCS_RC2_CBC_PARAMETERS
  2364. //  szOID_RSA_RC2CBC
  2365. //
  2366. //  pvStructInfo points to following CRYPT_RC2_CBC_PARAMETERS data structure.
  2367. //--------------------------------------------------------------------------
  2368. typedef struct _CRYPT_RC2_CBC_PARAMETERS {
  2369.     DWORD               dwVersion;
  2370.     BOOL                fIV;            // set if has following IV
  2371.     BYTE                rgbIV[8];
  2372. } CRYPT_RC2_CBC_PARAMETERS, *PCRYPT_RC2_CBC_PARAMETERS;
  2373.  
  2374. #define CRYPT_RC2_40BIT_VERSION     160
  2375. #define CRYPT_RC2_64BIT_VERSION     120
  2376. #define CRYPT_RC2_128BIT_VERSION    58
  2377.  
  2378.  
  2379. //+-------------------------------------------------------------------------
  2380. //  PKCS_SMIME_CAPABILITIES
  2381. //  szOID_RSA_SMIMECapabilities
  2382. //
  2383. //  pvStructInfo points to following CRYPT_SMIME_CAPABILITIES data structure.
  2384. //
  2385. //  Note, for CryptEncodeObject(X509_ASN_ENCODING), Parameters.cbData == 0
  2386. //  causes the encoded parameters to be omitted and not encoded as a NULL
  2387. //  (05 00) as is done when encoding a CRYPT_ALGORITHM_IDENTIFIER. This
  2388. //  is per the SMIME specification for encoding capabilities.
  2389. //--------------------------------------------------------------------------
  2390. typedef struct _CRYPT_SMIME_CAPABILITY {
  2391.     LPSTR               pszObjId;
  2392.     CRYPT_OBJID_BLOB    Parameters;
  2393. } CRYPT_SMIME_CAPABILITY, *PCRYPT_SMIME_CAPABILITY;
  2394.  
  2395. typedef struct _CRYPT_SMIME_CAPABILITIES {
  2396.     DWORD                   cCapability;
  2397.     PCRYPT_SMIME_CAPABILITY rgCapability;
  2398. } CRYPT_SMIME_CAPABILITIES, *PCRYPT_SMIME_CAPABILITIES;
  2399.  
  2400.  
  2401. //+-------------------------------------------------------------------------
  2402. //  PKCS7_SIGNER_INFO
  2403. //
  2404. //  pvStructInfo points to CMSG_SIGNER_INFO.
  2405. //--------------------------------------------------------------------------
  2406.  
  2407.  
  2408. //+-------------------------------------------------------------------------
  2409. //  Netscape Certificate Extension Object Identifiers
  2410. //--------------------------------------------------------------------------
  2411. #define szOID_NETSCAPE                  "2.16.840.1.113730"
  2412. #define szOID_NETSCAPE_CERT_EXTENSION   "2.16.840.1.113730.1"
  2413. #define szOID_NETSCAPE_CERT_TYPE        "2.16.840.1.113730.1.1"
  2414. #define szOID_NETSCAPE_BASE_URL         "2.16.840.1.113730.1.2"
  2415. #define szOID_NETSCAPE_REVOCATION_URL   "2.16.840.1.113730.1.3"
  2416. #define szOID_NETSCAPE_CA_REVOCATION_URL "2.16.840.1.113730.1.4"
  2417. #define szOID_NETSCAPE_CERT_RENEWAL_URL "2.16.840.1.113730.1.7"
  2418. #define szOID_NETSCAPE_CA_POLICY_URL    "2.16.840.1.113730.1.8"
  2419. #define szOID_NETSCAPE_SSL_SERVER_NAME  "2.16.840.1.113730.1.12"
  2420. #define szOID_NETSCAPE_COMMENT          "2.16.840.1.113730.1.13"
  2421.  
  2422. //+-------------------------------------------------------------------------
  2423. //  Netscape Certificate Data Type Object Identifiers
  2424. //--------------------------------------------------------------------------
  2425. #define szOID_NETSCAPE_DATA_TYPE        "2.16.840.1.113730.2"
  2426. #define szOID_NETSCAPE_CERT_SEQUENCE    "2.16.840.1.113730.2.5"
  2427.  
  2428.  
  2429. //+-------------------------------------------------------------------------
  2430. //  szOID_NETSCAPE_CERT_TYPE extension
  2431. //
  2432. //  Its value is a bit string. CryptDecodeObject/CryptEncodeObject using
  2433. //  X509_BITS.
  2434. //
  2435. //  The following bits are defined:
  2436. //--------------------------------------------------------------------------
  2437. #define NETSCAPE_SSL_CLIENT_AUTH_CERT_TYPE  0x80
  2438. #define NETSCAPE_SSL_SERVER_AUTH_CERT_TYPE  0x40
  2439. #define NETSCAPE_SSL_CA_CERT_TYPE           0x04
  2440.  
  2441. //+-------------------------------------------------------------------------
  2442. //  szOID_NETSCAPE_BASE_URL extension
  2443. //
  2444. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2445. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2446. //  dwValueType = CERT_RDN_IA5_STRING.
  2447. //
  2448. //  When present this string is added to the beginning of all relative URLs
  2449. //  in the certificate.  This extension can be considered an optimization
  2450. //  to reduce the size of the URL extensions.
  2451. //--------------------------------------------------------------------------
  2452.  
  2453. //+-------------------------------------------------------------------------
  2454. //  szOID_NETSCAPE_REVOCATION_URL extension
  2455. //
  2456. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2457. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2458. //  dwValueType = CERT_RDN_IA5_STRING.
  2459. //
  2460. //  It is a relative or absolute URL that can be used to check the
  2461. //  revocation status of a certificate. The revocation check will be
  2462. //  performed as an HTTP GET method using a url that is the concatenation of
  2463. //  revocation-url and certificate-serial-number.
  2464. //  Where the certificate-serial-number is encoded as a string of
  2465. //  ascii hexadecimal digits. For example, if the netscape-base-url is
  2466. //  https://www.certs-r-us.com/, the netscape-revocation-url is
  2467. //  cgi-bin/check-rev.cgi?, and the certificate serial number is 173420,
  2468. //  the resulting URL would be:
  2469. //  https://www.certs-r-us.com/cgi-bin/check-rev.cgi?02a56c
  2470. //
  2471. //  The server should return a document with a Content-Type of
  2472. //  application/x-netscape-revocation.  The document should contain
  2473. //  a single ascii digit, '1' if the certificate is not curently valid,
  2474. //  and '0' if it is curently valid.
  2475. //
  2476. //  Note: for all of the URLs that include the certificate serial number,
  2477. //  the serial number will be encoded as a string which consists of an even
  2478. //  number of hexadecimal digits.  If the number of significant digits is odd,
  2479. //  the string will have a single leading zero to ensure an even number of
  2480. //  digits is generated.
  2481. //--------------------------------------------------------------------------
  2482.  
  2483. //+-------------------------------------------------------------------------
  2484. //  szOID_NETSCAPE_CA_REVOCATION_URL extension
  2485. //
  2486. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2487. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2488. //  dwValueType = CERT_RDN_IA5_STRING.
  2489. //
  2490. //  It is a relative or absolute URL that can be used to check the
  2491. //  revocation status of any certificates that are signed by the CA that
  2492. //  this certificate belongs to. This extension is only valid in CA
  2493. //  certificates.  The use of this extension is the same as the above
  2494. //  szOID_NETSCAPE_REVOCATION_URL extension.
  2495. //--------------------------------------------------------------------------
  2496.  
  2497. //+-------------------------------------------------------------------------
  2498. //  szOID_NETSCAPE_CERT_RENEWAL_URL extension
  2499. //
  2500. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2501. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2502. //  dwValueType = CERT_RDN_IA5_STRING.
  2503. //
  2504. //  It is a relative or absolute URL that points to a certificate renewal
  2505. //  form. The renewal form will be accessed with an HTTP GET method using a
  2506. //  url that is the concatenation of renewal-url and
  2507. //  certificate-serial-number. Where the certificate-serial-number is
  2508. //  encoded as a string of ascii hexadecimal digits. For example, if the
  2509. //  netscape-base-url is https://www.certs-r-us.com/, the
  2510. //  netscape-cert-renewal-url is cgi-bin/check-renew.cgi?, and the
  2511. //  certificate serial number is 173420, the resulting URL would be:
  2512. //  https://www.certs-r-us.com/cgi-bin/check-renew.cgi?02a56c
  2513. //  The document returned should be an HTML form that will allow the user
  2514. //  to request a renewal of their certificate.
  2515. //--------------------------------------------------------------------------
  2516.  
  2517. //+-------------------------------------------------------------------------
  2518. //  szOID_NETSCAPE_CA_POLICY_URL extension
  2519. //
  2520. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2521. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2522. //  dwValueType = CERT_RDN_IA5_STRING.
  2523. //
  2524. //  It is a relative or absolute URL that points to a web page that
  2525. //  describes the policies under which the certificate was issued.
  2526. //--------------------------------------------------------------------------
  2527.  
  2528. //+-------------------------------------------------------------------------
  2529. //  szOID_NETSCAPE_SSL_SERVER_NAME extension
  2530. //
  2531. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2532. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2533. //  dwValueType = CERT_RDN_IA5_STRING.
  2534. //
  2535. //  It is a "shell expression" that can be used to match the hostname of the
  2536. //  SSL server that is using this certificate.  It is recommended that if
  2537. //  the server's hostname does not match this pattern the user be notified
  2538. //  and given the option to terminate the SSL connection.  If this extension
  2539. //  is not present then the CommonName in the certificate subject's
  2540. //  distinguished name is used for the same purpose.
  2541. //--------------------------------------------------------------------------
  2542.  
  2543. //+-------------------------------------------------------------------------
  2544. //  szOID_NETSCAPE_COMMENT extension
  2545. //
  2546. //  Its value is an IA5_STRING. CryptDecodeObject/CryptEncodeObject using
  2547. //  X509_ANY_STRING or X509_UNICODE_ANY_STRING, where,
  2548. //  dwValueType = CERT_RDN_IA5_STRING.
  2549. //
  2550. //  It is a comment that may be displayed to the user when the certificate
  2551. //  is viewed.
  2552. //--------------------------------------------------------------------------
  2553.  
  2554. //+-------------------------------------------------------------------------
  2555. //  szOID_NETSCAPE_CERT_SEQUENCE
  2556. //
  2557. //  Its value is a PKCS#7 ContentInfo structure wrapping a sequence of
  2558. //  certificates. The value of the contentType field is
  2559. //  szOID_NETSCAPE_CERT_SEQUENCE, while the content field is the following
  2560. //  structure:
  2561. //      CertificateSequence ::= SEQUENCE OF Certificate.
  2562. //
  2563. //  CryptDecodeObject/CryptEncodeObject using
  2564. //  PKCS_CONTENT_INFO_SEQUENCE_OF_ANY, where,
  2565. //  pszObjId = szOID_NETSCAPE_CERT_SEQUENCE and the CRYPT_DER_BLOBs point
  2566. //  to encoded X509 certificates.
  2567. //--------------------------------------------------------------------------
  2568.  
  2569.  
  2570. //+=========================================================================
  2571. //  Object IDentifier (OID) Installable Functions:  Data Structures and APIs
  2572. //==========================================================================
  2573.  
  2574. typedef void *HCRYPTOIDFUNCSET;
  2575. typedef void *HCRYPTOIDFUNCADDR;
  2576.  
  2577. // Predefined OID Function Names
  2578. #define CRYPT_OID_ENCODE_OBJECT_FUNC        "CryptDllEncodeObject"
  2579. #define CRYPT_OID_DECODE_OBJECT_FUNC        "CryptDllDecodeObject"
  2580. #define CRYPT_OID_CREATE_COM_OBJECT_FUNC    "CryptDllCreateCOMObject"
  2581. #define CRYPT_OID_VERIFY_REVOCATION_FUNC    "CertDllVerifyRevocation"
  2582. #define CRYPT_OID_VERIFY_CTL_USAGE_FUNC     "CertDllVerifyCTLUsage"
  2583. #define CRYPT_OID_FORMAT_OBJECT_FUNC        "CryptDllFormatObject"
  2584. #define CRYPT_OID_FIND_OID_INFO_FUNC        "CryptDllFindOIDInfo"
  2585.  
  2586. // CryptDllEncodeObject has same function signature as CryptEncodeObject.
  2587.  
  2588. // CryptDllDecodeObject has same function signature as CryptDecodeObject.
  2589.  
  2590. // CryptDllCreateCOMObject has the following signature:
  2591. //      BOOL WINAPI CryptDllCreateCOMObject(
  2592. //          IN DWORD dwEncodingType,
  2593. //          IN LPCSTR pszOID,
  2594. //          IN PCRYPT_DATA_BLOB pEncodedContent,
  2595. //          IN DWORD dwFlags,
  2596. //          IN REFIID riid,
  2597. //          OUT void **ppvObj);
  2598.  
  2599. // CertDllVerifyRevocation has the same signature as CertVerifyRevocation
  2600. //  (See CertVerifyRevocation for details on when called)
  2601.  
  2602. // CertDllVerifyCTLUsage has the same signature as CertVerifyCTLUsage
  2603.  
  2604. // CryptDllFindOIDInfo currently is only used to store values used by
  2605. // CryptFindOIDInfo. See CryptFindOIDInfo() for more details.
  2606.  
  2607. //  Example of a complete OID Function Registry Name:
  2608. //    HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\OID
  2609. //      Encoding Type 1\CryptDllEncodeObject\1.2.3
  2610. //
  2611. //  The key's L"Dll" value contains the name of the Dll.
  2612. //  The key's L"FuncName" value overrides the default function name
  2613. #define CRYPT_OID_REGPATH "Software\\Microsoft\\Cryptography\\OID"
  2614. #define CRYPT_OID_REG_ENCODING_TYPE_PREFIX  "EncodingType "
  2615. #define CRYPT_OID_REG_DLL_VALUE_NAME        L"Dll"
  2616. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME  L"FuncName"
  2617. #define CRYPT_OID_REG_FUNC_NAME_VALUE_NAME_A "FuncName"
  2618.  
  2619. // OID used for Default OID functions
  2620. #define CRYPT_DEFAULT_OID                   "DEFAULT"
  2621.  
  2622. typedef struct _CRYPT_OID_FUNC_ENTRY {
  2623.     LPCSTR  pszOID;
  2624.     void    *pvFuncAddr;
  2625. } CRYPT_OID_FUNC_ENTRY, *PCRYPT_OID_FUNC_ENTRY;
  2626.  
  2627.  
  2628. #define CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG  1
  2629.  
  2630. //+-------------------------------------------------------------------------
  2631. //  Install a set of callable OID function addresses.
  2632. //
  2633. //  By default the functions are installed at end of the list.
  2634. //  Set CRYPT_INSTALL_OID_FUNC_BEFORE_FLAG to install at beginning of list.
  2635. //
  2636. //  hModule should be updated with the hModule passed to DllMain to prevent
  2637. //  the Dll containing the function addresses from being unloaded by
  2638. //  CryptGetOIDFuncAddress/CryptFreeOIDFunctionAddress. This would be the
  2639. //  case when the Dll has also regsvr32'ed OID functions via
  2640. //  CryptRegisterOIDFunction.
  2641. //
  2642. //  DEFAULT functions are installed by setting rgFuncEntry[].pszOID =
  2643. //  CRYPT_DEFAULT_OID.
  2644. //--------------------------------------------------------------------------
  2645. WINCRYPT32API
  2646. BOOL
  2647. WINAPI
  2648. CryptInstallOIDFunctionAddress(
  2649.     IN HMODULE hModule,         // hModule passed to DllMain
  2650.     IN DWORD dwEncodingType,
  2651.     IN LPCSTR pszFuncName,
  2652.     IN DWORD cFuncEntry,
  2653.     IN const CRYPT_OID_FUNC_ENTRY rgFuncEntry[],
  2654.     IN DWORD dwFlags
  2655.     );
  2656.  
  2657. //+-------------------------------------------------------------------------
  2658. //  Initialize and return handle to the OID function set identified by its
  2659. //  function name.
  2660. //
  2661. //  If the set already exists, a handle to the existing set is returned.
  2662. //--------------------------------------------------------------------------
  2663. WINCRYPT32API
  2664. HCRYPTOIDFUNCSET
  2665. WINAPI
  2666. CryptInitOIDFunctionSet(
  2667.     IN LPCSTR pszFuncName,
  2668.     IN DWORD dwFlags
  2669.     );
  2670.  
  2671. //+-------------------------------------------------------------------------
  2672. //  Search the list of installed functions for an encoding type and OID match.
  2673. //  If not found, search the registry.
  2674. //
  2675. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  2676. //  address and *phFuncAddr updated with the function address's handle.
  2677. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2678. //  be called to release it.
  2679. //
  2680. //  For a registry match, the Dll containing the function is loaded.
  2681. //--------------------------------------------------------------------------
  2682. WINCRYPT32API
  2683. BOOL
  2684. WINAPI
  2685. CryptGetOIDFunctionAddress(
  2686.     IN HCRYPTOIDFUNCSET hFuncSet,
  2687.     IN DWORD dwEncodingType,
  2688.     IN LPCSTR pszOID,
  2689.     IN DWORD dwFlags,
  2690.     OUT void **ppvFuncAddr,
  2691.     OUT HCRYPTOIDFUNCADDR *phFuncAddr
  2692.     );
  2693.  
  2694.  
  2695. //+-------------------------------------------------------------------------
  2696. //  Get the list of registered default Dll entries for the specified
  2697. //  function set and encoding type.
  2698. //
  2699. //  The returned list consists of none, one or more null terminated Dll file
  2700. //  names. The list is terminated with an empty (L"\0") Dll file name.
  2701. //  For example: L"first.dll" L"\0" L"second.dll" L"\0" L"\0"
  2702. //--------------------------------------------------------------------------
  2703. WINCRYPT32API
  2704. BOOL
  2705. WINAPI
  2706. CryptGetDefaultOIDDllList(
  2707.     IN HCRYPTOIDFUNCSET hFuncSet,
  2708.     IN DWORD dwEncodingType,
  2709.     OUT LPWSTR pwszDllList,
  2710.     IN OUT DWORD *pcchDllList
  2711.     );
  2712.  
  2713. //+-------------------------------------------------------------------------
  2714. //  Either: get the first or next installed DEFAULT function OR
  2715. //  load the Dll containing the DEFAULT function.
  2716. //
  2717. //  If pwszDll is NULL, search the list of installed DEFAULT functions.
  2718. //  *phFuncAddr must be set to NULL to get the first installed function.
  2719. //  Successive installed functions are returned by setting *phFuncAddr
  2720. //  to the hFuncAddr returned by the previous call.
  2721. //
  2722. //  If pwszDll is NULL, the input *phFuncAddr
  2723. //  is always CryptFreeOIDFunctionAddress'ed by this function, even for
  2724. //  an error.
  2725. //
  2726. //  If pwszDll isn't NULL, then, attempts to load the Dll and the DEFAULT
  2727. //  function. *phFuncAddr is ignored upon entry and isn't
  2728. //  CryptFreeOIDFunctionAddress'ed.
  2729. //
  2730. //  For success, returns TRUE with *ppvFuncAddr updated with the function's
  2731. //  address and *phFuncAddr updated with the function address's handle.
  2732. //  The function's handle is AddRef'ed. CryptFreeOIDFunctionAddress needs to
  2733. //  be called to release it or CryptGetDefaultOIDFunctionAddress can also
  2734. //  be called for a NULL pwszDll.
  2735. //--------------------------------------------------------------------------
  2736. WINCRYPT32API
  2737. BOOL
  2738. WINAPI
  2739. CryptGetDefaultOIDFunctionAddress(
  2740.     IN HCRYPTOIDFUNCSET hFuncSet,
  2741.     IN DWORD dwEncodingType,
  2742.     IN OPTIONAL LPCWSTR pwszDll,
  2743.     IN DWORD dwFlags,
  2744.     OUT void **ppvFuncAddr,
  2745.     IN OUT HCRYPTOIDFUNCADDR *phFuncAddr
  2746.     );
  2747.  
  2748. //+-------------------------------------------------------------------------
  2749. //  Releases the handle AddRef'ed and returned by CryptGetOIDFunctionAddress
  2750. //  or CryptGetDefaultOIDFunctionAddress.
  2751. //
  2752. //  If a Dll was loaded for the function its unloaded. However, before doing
  2753. //  the unload, the DllCanUnloadNow function exported by the loaded Dll is
  2754. //  called. It should return S_FALSE to inhibit the unload or S_TRUE to enable
  2755. //  the unload. If the Dll doesn't export DllCanUnloadNow, the Dll is unloaded.
  2756. //
  2757. //  DllCanUnloadNow has the following signature:
  2758. //      STDAPI  DllCanUnloadNow(void);
  2759. //--------------------------------------------------------------------------
  2760. WINCRYPT32API
  2761. BOOL
  2762. WINAPI
  2763. CryptFreeOIDFunctionAddress(
  2764.     IN HCRYPTOIDFUNCADDR hFuncAddr,
  2765.     IN DWORD dwFlags
  2766.     );
  2767.  
  2768. //+-------------------------------------------------------------------------
  2769. //  Register the Dll containing the function to be called for the specified
  2770. //  encoding type, function name and OID.
  2771. //
  2772. //  pwszDll may contain environment-variable strings
  2773. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2774. //
  2775. //  In addition to registering the DLL, you may override the
  2776. //  name of the function to be called. For example,
  2777. //      pszFuncName = "CryptDllEncodeObject",
  2778. //      pszOverrideFuncName = "MyEncodeXyz".
  2779. //  This allows a Dll to export multiple OID functions for the same
  2780. //  function name without needing to interpose its own OID dispatcher function.
  2781. //--------------------------------------------------------------------------
  2782. WINCRYPT32API
  2783. BOOL
  2784. WINAPI
  2785. CryptRegisterOIDFunction(
  2786.     IN DWORD dwEncodingType,
  2787.     IN LPCSTR pszFuncName,
  2788.     IN LPCSTR pszOID,
  2789.     IN OPTIONAL LPCWSTR pwszDll,
  2790.     IN OPTIONAL LPCSTR pszOverrideFuncName
  2791.     );
  2792.  
  2793. //+-------------------------------------------------------------------------
  2794. //  Unregister the Dll containing the function to be called for the specified
  2795. //  encoding type, function name and OID.
  2796. //--------------------------------------------------------------------------
  2797. WINCRYPT32API
  2798. BOOL
  2799. WINAPI
  2800. CryptUnregisterOIDFunction(
  2801.     IN DWORD dwEncodingType,
  2802.     IN LPCSTR pszFuncName,
  2803.     IN LPCSTR pszOID
  2804.     );
  2805.  
  2806.  
  2807. //+-------------------------------------------------------------------------
  2808. //  Register the Dll containing the default function to be called for the
  2809. //  specified encoding type and function name.
  2810. //
  2811. //  Unlike CryptRegisterOIDFunction, you can't override the function name
  2812. //  needing to be exported by the Dll.
  2813. //
  2814. //  The Dll is inserted before the entry specified by dwIndex.
  2815. //    dwIndex == 0, inserts at the beginning.
  2816. //    dwIndex == CRYPT_REGISTER_LAST_INDEX, appends at the end.
  2817. //
  2818. //  pwszDll may contain environment-variable strings
  2819. //  which are ExpandEnvironmentStrings()'ed before loading the Dll.
  2820. //--------------------------------------------------------------------------
  2821. WINCRYPT32API
  2822. BOOL
  2823. WINAPI
  2824. CryptRegisterDefaultOIDFunction(
  2825.     IN DWORD dwEncodingType,
  2826.     IN LPCSTR pszFuncName,
  2827.     IN DWORD dwIndex,
  2828.     IN LPCWSTR pwszDll
  2829.     );
  2830.  
  2831. #define CRYPT_REGISTER_FIRST_INDEX   0
  2832. #define CRYPT_REGISTER_LAST_INDEX    0xFFFFFFFF
  2833.  
  2834. //+-------------------------------------------------------------------------
  2835. //  Unregister the Dll containing the default function to be called for
  2836. //  the specified encoding type and function name.
  2837. //--------------------------------------------------------------------------
  2838. WINCRYPT32API
  2839. BOOL
  2840. WINAPI
  2841. CryptUnregisterDefaultOIDFunction(
  2842.     IN DWORD dwEncodingType,
  2843.     IN LPCSTR pszFuncName,
  2844.     IN LPCWSTR pwszDll
  2845.     );
  2846.  
  2847. //+-------------------------------------------------------------------------
  2848. //  Set the value for the specified encoding type, function name, OID and
  2849. //  value name.
  2850. //
  2851. //  See RegSetValueEx for the possible value types.
  2852. //
  2853. //  String types are UNICODE.
  2854. //--------------------------------------------------------------------------
  2855. WINCRYPT32API
  2856. BOOL
  2857. WINAPI
  2858. CryptSetOIDFunctionValue(
  2859.     IN DWORD dwEncodingType,
  2860.     IN LPCSTR pszFuncName,
  2861.     IN LPCSTR pszOID,
  2862.     IN LPCWSTR pwszValueName,
  2863.     IN DWORD dwValueType,
  2864.     IN const BYTE *pbValueData,
  2865.     IN DWORD cbValueData
  2866.     );
  2867.  
  2868. //+-------------------------------------------------------------------------
  2869. //  Get the value for the specified encoding type, function name, OID and
  2870. //  value name.
  2871. //
  2872. //  See RegEnumValue for the possible value types.
  2873. //
  2874. //  String types are UNICODE.
  2875. //--------------------------------------------------------------------------
  2876. WINCRYPT32API
  2877. BOOL
  2878. WINAPI
  2879. CryptGetOIDFunctionValue(
  2880.     IN DWORD dwEncodingType,
  2881.     IN LPCSTR pszFuncName,
  2882.     IN LPCSTR pszOID,
  2883.     IN LPCWSTR pwszValueName,
  2884.     OUT DWORD *pdwValueType,
  2885.     OUT BYTE *pbValueData,
  2886.     IN OUT DWORD *pcbValueData
  2887.     );
  2888.  
  2889. typedef BOOL (WINAPI *PFN_CRYPT_ENUM_OID_FUNC)(
  2890.         IN DWORD dwEncodingType,
  2891.         IN LPCSTR pszFuncName,
  2892.         IN LPCSTR pszOID,
  2893.         IN DWORD cValue,
  2894.         IN const DWORD rgdwValueType[],
  2895.         IN LPCWSTR const rgpwszValueName[],
  2896.         IN const BYTE * const rgpbValueData[],
  2897.         IN const DWORD rgcbValueData[],
  2898.         IN void *pvArg
  2899.         );
  2900.  
  2901. //+-------------------------------------------------------------------------
  2902. //  Enumerate the OID functions identified by their encoding type,
  2903. //  function name and OID.
  2904. //
  2905. //  pfnEnumOIDFunc is called for each registry key matching the input
  2906. //  parameters. Setting dwEncodingType to CRYPT_MATCH_ANY_ENCODING_TYPE matches
  2907. //  any. Setting pszFuncName or pszOID to NULL matches any.
  2908. //
  2909. //  Set pszOID == CRYPT_DEFAULT_OID to restrict the enumeration to only the
  2910. //  DEFAULT functions
  2911. //
  2912. //  String types are UNICODE.
  2913. //--------------------------------------------------------------------------
  2914. WINCRYPT32API
  2915. BOOL
  2916. WINAPI
  2917. CryptEnumOIDFunction(
  2918.     IN DWORD dwEncodingType,
  2919.     IN OPTIONAL LPCSTR pszFuncName,
  2920.     IN OPTIONAL LPCSTR pszOID,
  2921.     IN DWORD dwFlags,
  2922.     IN void *pvArg,
  2923.     IN PFN_CRYPT_ENUM_OID_FUNC pfnEnumOIDFunc
  2924.     );
  2925.  
  2926. #define CRYPT_MATCH_ANY_ENCODING_TYPE   0xFFFFFFFF
  2927.  
  2928.  
  2929. //+=========================================================================
  2930. //  Object IDentifier (OID) Information:  Data Structures and APIs
  2931. //==========================================================================
  2932.  
  2933. //+-------------------------------------------------------------------------
  2934. //  OID Information
  2935. //--------------------------------------------------------------------------
  2936. typedef struct _CRYPT_OID_INFO {
  2937.     DWORD               cbSize;
  2938.     LPCSTR              pszOID;
  2939.     LPCWSTR             pwszName;
  2940.     DWORD               dwGroupId;
  2941.     union {
  2942.         DWORD               dwValue;
  2943.         ALG_ID              Algid;
  2944.         DWORD               dwLength;
  2945.     };
  2946.     CRYPT_DATA_BLOB     ExtraInfo;
  2947. } CRYPT_OID_INFO, *PCRYPT_OID_INFO;
  2948. typedef const CRYPT_OID_INFO CCRYPT_OID_INFO, *PCCRYPT_OID_INFO;
  2949.  
  2950. //+-------------------------------------------------------------------------
  2951. //  OID Group IDs
  2952. //--------------------------------------------------------------------------
  2953. #define CRYPT_HASH_ALG_OID_GROUP_ID             1
  2954. #define CRYPT_ENCRYPT_ALG_OID_GROUP_ID          2
  2955. #define CRYPT_PUBKEY_ALG_OID_GROUP_ID           3
  2956. #define CRYPT_SIGN_ALG_OID_GROUP_ID             4
  2957. #define CRYPT_RDN_ATTR_OID_GROUP_ID             5
  2958. #define CRYPT_EXT_OR_ATTR_OID_GROUP_ID          6
  2959. #define CRYPT_ENHKEY_USAGE_OID_GROUP_ID         7
  2960. #define CRYPT_POLICY_OID_GROUP_ID               8
  2961. #define CRYPT_LAST_OID_GROUP_ID                 8
  2962.  
  2963. #define CRYPT_FIRST_ALG_OID_GROUP_ID            CRYPT_HASH_ALG_OID_GROUP_ID
  2964. #define CRYPT_LAST_ALG_OID_GROUP_ID             CRYPT_SIGN_ALG_OID_GROUP_ID
  2965.  
  2966.  
  2967. // The CRYPT_*_ALG_OID_GROUP_ID's have an Algid. The CRYPT_RDN_ATTR_OID_GROUP_ID
  2968. // has a dwLength. The CRYPT_EXT_OR_ATTR_OID_GROUP_ID,
  2969. // CRYPT_ENHKEY_USAGE_OID_GROUP_ID or CRYPT_POLICY_OID_GROUP_ID don't have a
  2970. // dwValue.
  2971. //
  2972.  
  2973. // CRYPT_PUBKEY_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2974. //  DWORD[0] - Flags. CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG can be set to
  2975. //             inhibit the reformatting of the signature before
  2976. //             CryptVerifySignature is called or after CryptSignHash
  2977. //             is called. CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG can
  2978. //             be set to include the public key algorithm's parameters
  2979. //             in the PKCS7's digestEncryptionAlgorithm's parameters.
  2980.  
  2981. #define CRYPT_OID_INHIBIT_SIGNATURE_FORMAT_FLAG     0x1
  2982. #define CRYPT_OID_USE_PUBKEY_PARA_FOR_PKCS7_FLAG    0x2
  2983.  
  2984. // CRYPT_SIGN_ALG_OID_GROUP_ID has the following optional ExtraInfo:
  2985. //  DWORD[0] - Public Key Algid.
  2986. //  DWORD[1] - Flags. Same as above for CRYPT_PUBKEY_ALG_OID_GROUP_ID.
  2987.  
  2988. // CRYPT_RDN_ATTR_OID_GROUP_ID has the following optional ExtraInfo:
  2989. //  Array of DWORDs:
  2990. //   [0 ..] - Null terminated list of acceptable RDN attribute
  2991. //            value types. An empty list implies CERT_RDN_PRINTABLE_STRING,
  2992. //            CERT_RDN_T61_STRING, 0.
  2993.  
  2994. //+-------------------------------------------------------------------------
  2995. //  Find OID information. Returns NULL if unable to find any information
  2996. //  for the specified key and group. Note, returns a pointer to a constant
  2997. //  data structure. The returned pointer MUST NOT be freed.
  2998. //
  2999. //  dwKeyType's:
  3000. //    CRYPT_OID_INFO_OID_KEY, pvKey points to a szOID
  3001. //    CRYPT_OID_INFO_NAME_KEY, pvKey points to a wszName
  3002. //    CRYPT_OID_INFO_ALGID_KEY, pvKey points to an ALG_ID
  3003. //    CRYPT_OID_INFO_SIGN_KEY, pvKey points to an array of two ALG_ID's:
  3004. //      ALG_ID[0] - Hash Algid
  3005. //      ALG_ID[1] - PubKey Algid
  3006. //
  3007. //  Setting dwGroupId to 0, searches all groups according to the dwKeyType.
  3008. //  Otherwise, only the dwGroupId is searched.
  3009. //--------------------------------------------------------------------------
  3010. WINCRYPT32API
  3011. PCCRYPT_OID_INFO
  3012. WINAPI
  3013. CryptFindOIDInfo(
  3014.     IN DWORD dwKeyType,
  3015.     IN void *pvKey,
  3016.     IN DWORD dwGroupId
  3017.     );
  3018.  
  3019. #define CRYPT_OID_INFO_OID_KEY           1
  3020. #define CRYPT_OID_INFO_NAME_KEY          2
  3021. #define CRYPT_OID_INFO_ALGID_KEY         3
  3022. #define CRYPT_OID_INFO_SIGN_KEY          4
  3023.  
  3024. //+-------------------------------------------------------------------------
  3025. //  Register OID information. The OID information specified in the
  3026. //  CCRYPT_OID_INFO structure is persisted to the registry.
  3027. //
  3028. //  crypt32.dll contains information for the commonly known OIDs. This function
  3029. //  allows applications to augment crypt32.dll's OID information. During
  3030. //  CryptFindOIDInfo's first call, the registered OID information is installed.
  3031. //
  3032. //  By default the registered OID information is installed after crypt32.dll's
  3033. //  OID entries. Set CRYPT_INSTALL_OID_INFO_BEFORE_FLAG to install before.
  3034. //--------------------------------------------------------------------------
  3035. WINCRYPT32API
  3036. BOOL
  3037. WINAPI
  3038. CryptRegisterOIDInfo(
  3039.     IN PCCRYPT_OID_INFO pInfo,
  3040.     IN DWORD dwFlags
  3041.     );
  3042.  
  3043. #define CRYPT_INSTALL_OID_INFO_BEFORE_FLAG  1
  3044.  
  3045. //+-------------------------------------------------------------------------
  3046. //  Unregister OID information. Only the pszOID and dwGroupId fields are
  3047. //  used to identify the OID information to be unregistered.
  3048. //--------------------------------------------------------------------------
  3049. WINCRYPT32API
  3050. BOOL
  3051. WINAPI
  3052. CryptUnregisterOIDInfo(
  3053.     IN PCCRYPT_OID_INFO pInfo
  3054.     );
  3055.  
  3056.  
  3057. //+=========================================================================
  3058. //  Low Level Cryptographic Message Data Structures and APIs
  3059. //==========================================================================
  3060.  
  3061. typedef void *HCRYPTMSG;
  3062.  
  3063. #define szOID_PKCS_7_DATA               "1.2.840.113549.1.7.1"
  3064. #define szOID_PKCS_7_SIGNED             "1.2.840.113549.1.7.2"
  3065. #define szOID_PKCS_7_ENVELOPED          "1.2.840.113549.1.7.3"
  3066. #define szOID_PKCS_7_SIGNEDANDENVELOPED "1.2.840.113549.1.7.4"
  3067. #define szOID_PKCS_7_DIGESTED           "1.2.840.113549.1.7.5"
  3068. #define szOID_PKCS_7_ENCRYPTED          "1.2.840.113549.1.7.6"
  3069.  
  3070. #define szOID_PKCS_9_CONTENT_TYPE       "1.2.840.113549.1.9.3"
  3071. #define szOID_PKCS_9_MESSAGE_DIGEST     "1.2.840.113549.1.9.4"
  3072.  
  3073. //+-------------------------------------------------------------------------
  3074. //  Message types
  3075. //--------------------------------------------------------------------------
  3076. #define CMSG_DATA                    1
  3077. #define CMSG_SIGNED                  2
  3078. #define CMSG_ENVELOPED               3
  3079. #define CMSG_SIGNED_AND_ENVELOPED    4
  3080. #define CMSG_HASHED                  5
  3081. #define CMSG_ENCRYPTED               6
  3082.  
  3083. //+-------------------------------------------------------------------------
  3084. //  Message Type Bit Flags
  3085. //--------------------------------------------------------------------------
  3086. #define CMSG_ALL_FLAGS                   (~0UL)
  3087. #define CMSG_DATA_FLAG                   (1 << CMSG_DATA)
  3088. #define CMSG_SIGNED_FLAG                 (1 << CMSG_SIGNED)
  3089. #define CMSG_ENVELOPED_FLAG              (1 << CMSG_ENVELOPED)
  3090. #define CMSG_SIGNED_AND_ENVELOPED_FLAG   (1 << CMSG_SIGNED_AND_ENVELOPED)
  3091. #define CMSG_HASHED_FLAG                 (1 << CMSG_HASHED)
  3092. #define CMSG_ENCRYPTED_FLAG              (1 << CMSG_ENCRYPTED)
  3093.  
  3094. //+-------------------------------------------------------------------------
  3095. //  The message encode information (pvMsgEncodeInfo) is message type dependent
  3096. //--------------------------------------------------------------------------
  3097.  
  3098. //+-------------------------------------------------------------------------
  3099. //  CMSG_DATA: pvMsgEncodeInfo = NULL
  3100. //--------------------------------------------------------------------------
  3101.  
  3102. //+-------------------------------------------------------------------------
  3103. //  CMSG_SIGNED
  3104. //
  3105. //  The pCertInfo in the CMSG_SIGNER_ENCODE_INFO provides the Issuer, SerialNumber
  3106. //  and PublicKeyInfo.Algorithm. The PublicKeyInfo.Algorithm implicitly
  3107. //  specifies the HashEncryptionAlgorithm to be used.
  3108. //
  3109. //  The hCryptProv and dwKeySpec specify the private key to use. If dwKeySpec
  3110. //  == 0, then, defaults to AT_SIGNATURE.
  3111. //
  3112. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  3113. //--------------------------------------------------------------------------
  3114. typedef struct _CMSG_SIGNER_ENCODE_INFO {
  3115.     DWORD                       cbSize;
  3116.     PCERT_INFO                  pCertInfo;
  3117.     HCRYPTPROV                  hCryptProv;
  3118.     DWORD                       dwKeySpec;
  3119.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3120.     void                        *pvHashAuxInfo;
  3121.     DWORD                       cAuthAttr;
  3122.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  3123.     DWORD                       cUnauthAttr;
  3124.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  3125. } CMSG_SIGNER_ENCODE_INFO, *PCMSG_SIGNER_ENCODE_INFO;
  3126.  
  3127. typedef struct _CMSG_SIGNED_ENCODE_INFO {
  3128.     DWORD                       cbSize;
  3129.     DWORD                       cSigners;
  3130.     PCMSG_SIGNER_ENCODE_INFO    rgSigners;
  3131.     DWORD                       cCertEncoded;
  3132.     PCERT_BLOB                  rgCertEncoded;
  3133.     DWORD                       cCrlEncoded;
  3134.     PCRL_BLOB                   rgCrlEncoded;
  3135. } CMSG_SIGNED_ENCODE_INFO, *PCMSG_SIGNED_ENCODE_INFO;
  3136.  
  3137. //+-------------------------------------------------------------------------
  3138. //  CMSG_ENVELOPED
  3139. //
  3140. //  The PCERT_INFO for the rgRecipients provides the Issuer, SerialNumber
  3141. //  and PublicKeyInfo. The PublicKeyInfo.Algorithm implicitly
  3142. //  specifies the KeyEncryptionAlgorithm to be used.
  3143. //
  3144. //  The PublicKeyInfo.PublicKey in PCERT_INFO is used to encrypt the content
  3145. //  encryption key for the recipient.
  3146. //
  3147. //  hCryptProv is used to do the content encryption, recipient key encryption
  3148. //  and export. The hCryptProv's private keys aren't used.
  3149. //
  3150. //  Note: CAPI currently doesn't support more than one KeyEncryptionAlgorithm
  3151. //  per provider. This will need to be fixed.
  3152. //
  3153. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  3154. //--------------------------------------------------------------------------
  3155. typedef struct _CMSG_ENVELOPED_ENCODE_INFO {
  3156.     DWORD                       cbSize;
  3157.     HCRYPTPROV                  hCryptProv;
  3158.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  3159.     void                        *pvEncryptionAuxInfo;
  3160.     DWORD                       cRecipients;
  3161.     PCERT_INFO                  *rgpRecipients;
  3162. } CMSG_ENVELOPED_ENCODE_INFO, *PCMSG_ENVELOPED_ENCODE_INFO;
  3163.  
  3164. //+-------------------------------------------------------------------------
  3165. //  CMSG_SIGNED_AND_ENVELOPED
  3166. //
  3167. //  For PKCS #7, a signed and enveloped message doesn't have the
  3168. //  signer's authenticated or unauthenticated attributes. Otherwise, a
  3169. //  combination of the CMSG_SIGNED_ENCODE_INFO and CMSG_ENVELOPED_ENCODE_INFO.
  3170. //--------------------------------------------------------------------------
  3171. typedef struct _CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO {
  3172.     DWORD                       cbSize;
  3173.     CMSG_SIGNED_ENCODE_INFO     SignedInfo;
  3174.     CMSG_ENVELOPED_ENCODE_INFO  EnvelopedInfo;
  3175. } CMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO, *PCMSG_SIGNED_AND_ENVELOPED_ENCODE_INFO;
  3176.  
  3177. //+-------------------------------------------------------------------------
  3178. //  CMSG_HASHED
  3179. //
  3180. //  hCryptProv is used to do the hash. Doesn't need to use a private key.
  3181. //
  3182. //  If fDetachedHash is set, then, the encoded message doesn't contain
  3183. //  any content (its treated as NULL Data)
  3184. //
  3185. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  3186. //--------------------------------------------------------------------------
  3187. typedef struct _CMSG_HASHED_ENCODE_INFO {
  3188.     DWORD                       cbSize;
  3189.     HCRYPTPROV                  hCryptProv;
  3190.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3191.     void                        *pvHashAuxInfo;
  3192. } CMSG_HASHED_ENCODE_INFO, *PCMSG_HASHED_ENCODE_INFO;
  3193.  
  3194. //+-------------------------------------------------------------------------
  3195. //  CMSG_ENCRYPTED
  3196. //
  3197. //  The key used to encrypt the message is identified outside of the message
  3198. //  content (for example, password).
  3199. //
  3200. //  The content input to CryptMsgUpdate has already been encrypted.
  3201. //
  3202. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  3203. //--------------------------------------------------------------------------
  3204. typedef struct _CMSG_ENCRYPTED_ENCODE_INFO {
  3205.     DWORD                       cbSize;
  3206.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  3207.     void                        *pvEncryptionAuxInfo;
  3208. } CMSG_ENCRYPTED_ENCODE_INFO, *PCMSG_ENCRYPTED_ENCODE_INFO;
  3209.  
  3210. //+-------------------------------------------------------------------------
  3211. //  This parameter allows messages to be of variable length with streamed
  3212. //  output.
  3213. //
  3214. //  By default, messages are of a definite length and
  3215. //  CryptMsgGetParam(CMSG_CONTENT_PARAM) is
  3216. //  called to get the cryptographically processed content. Until closed,
  3217. //  the handle keeps a copy of the processed content.
  3218. //
  3219. //  With streamed output, the processed content can be freed as its streamed.
  3220. //
  3221. //  If the length of the content to be updated is known at the time of the
  3222. //  open, then, ContentLength should be set to that length. Otherwise, it
  3223. //  should be set to CMSG_INDEFINITE_LENGTH.
  3224. //--------------------------------------------------------------------------
  3225. typedef BOOL (WINAPI *PFN_CMSG_STREAM_OUTPUT)(
  3226.         IN const void *pvArg,
  3227.         IN BYTE *pbData,
  3228.         IN DWORD cbData,
  3229.         IN BOOL fFinal
  3230.         );
  3231.  
  3232. #define CMSG_INDEFINITE_LENGTH       (0xFFFFFFFF)
  3233.  
  3234. typedef struct _CMSG_STREAM_INFO {
  3235.     DWORD                   cbContent;
  3236.     PFN_CMSG_STREAM_OUTPUT  pfnStreamOutput;
  3237.     void                    *pvArg;
  3238. } CMSG_STREAM_INFO, *PCMSG_STREAM_INFO;
  3239.  
  3240. //+-------------------------------------------------------------------------
  3241. //  Open dwFlags
  3242. //--------------------------------------------------------------------------
  3243. #define CMSG_BARE_CONTENT_FLAG              0x00000001
  3244. #define CMSG_LENGTH_ONLY_FLAG               0x00000002
  3245. #define CMSG_DETACHED_FLAG                  0x00000004
  3246. #define CMSG_AUTHENTICATED_ATTRIBUTES_FLAG  0x00000008
  3247. #define CMSG_CONTENTS_OCTETS_FLAG           0x00000010
  3248. #define CMSG_MAX_LENGTH_FLAG                0x00000020
  3249.  
  3250. //+-------------------------------------------------------------------------
  3251. //  Open a cryptographic message for encoding
  3252. //
  3253. //  For PKCS #7:
  3254. //  If the content to be passed to CryptMsgUpdate has already
  3255. //  been message encoded (the input to CryptMsgUpdate is the streamed output
  3256. //  from another message encode), then, the CMSG_ENCODED_CONTENT_INFO_FLAG should
  3257. //  be set in dwFlags. If not set, then, the inner ContentType is Data and
  3258. //  the input to CryptMsgUpdate is treated as the inner Data type's Content,
  3259. //  a string of bytes.
  3260. //  If CMSG_BARE_CONTENT_FLAG is specified for a streamed message,
  3261. //  the streamed output will not have an outer ContentInfo wrapper. This
  3262. //  makes it suitable to be streamed into an enclosing message.
  3263. //
  3264. //  The pStreamInfo parameter needs to be set to stream the encoded message
  3265. //  output.
  3266. //--------------------------------------------------------------------------
  3267. WINCRYPT32API
  3268. HCRYPTMSG
  3269. WINAPI
  3270. CryptMsgOpenToEncode(
  3271.     IN DWORD dwMsgEncodingType,
  3272.     IN DWORD dwFlags,
  3273.     IN DWORD dwMsgType,
  3274.     IN void const *pvMsgEncodeInfo,
  3275.     IN OPTIONAL LPSTR pszInnerContentObjID,
  3276.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  3277.     );
  3278.  
  3279. //+-------------------------------------------------------------------------
  3280. //  Calculate the length of an encoded cryptographic message.
  3281. //
  3282. //  Calculates the length of the encoded message given the
  3283. //  message type, encoding parameters and total length of
  3284. //  the data to be updated. Note, this might not be the exact length. However,
  3285. //  it will always be greater than or equal to the actual length.
  3286. //--------------------------------------------------------------------------
  3287. WINCRYPT32API
  3288. DWORD
  3289. WINAPI
  3290. CryptMsgCalculateEncodedLength(
  3291.     IN DWORD dwMsgEncodingType,
  3292.     IN DWORD dwFlags,
  3293.     IN DWORD dwMsgType,
  3294.     IN void const *pvMsgEncodeInfo,
  3295.     IN OPTIONAL LPSTR pszInnerContentObjID,
  3296.     IN DWORD cbData
  3297.     );
  3298.  
  3299. //+-------------------------------------------------------------------------
  3300. //  Open a cryptographic message for decoding
  3301. //
  3302. //  For PKCS #7: if the inner ContentType isn't Data, then, the inner
  3303. //  ContentInfo consisting of both ContentType and Content is output.
  3304. //  To also enable ContentInfo output for the Data ContentType, then,
  3305. //  the CMSG_ENCODED_CONTENT_INFO_FLAG should be set
  3306. //  in dwFlags. If not set, then, only the content portion of the inner
  3307. //  ContentInfo is output for the Data ContentType.
  3308. //
  3309. //  To only calculate the length of the decoded message, set the
  3310. //  CMSG_LENGTH_ONLY_FLAG in dwFlags. After the final CryptMsgUpdate get the
  3311. //  MSG_CONTENT_PARAM. Note, this might not be the exact length. However,
  3312. //  it will always be greater than or equal to the actual length.
  3313. //
  3314. //  hCryptProv specifies the crypto provider to use for hashing and/or
  3315. //  decrypting the message. For enveloped messages, hCryptProv also specifies
  3316. //  the private exchange key to use. For signed messages, hCryptProv is used
  3317. //  when CryptMsgVerifySigner is called.
  3318. //
  3319. //  For enveloped messages, the pRecipientInfo contains the Issuer and
  3320. //  SerialNumber identifying the RecipientInfo in the message.
  3321. //
  3322. //  Note, the pRecipientInfo should correspond to the provider's private
  3323. //  exchange key.
  3324. //
  3325. //  If pRecipientInfo is NULL, then, the message isn't decrypted. To decrypt
  3326. //  the message, CryptMsgControl(CMSG_CTRL_DECRYPT) is called after the final
  3327. //  CryptMsgUpdate.
  3328. //
  3329. //  The pStreamInfo parameter needs to be set to stream the decoded content
  3330. //  output. Note, if pRecipientInfo is NULL, then, the streamed output isn't
  3331. //  decrypted.
  3332. //--------------------------------------------------------------------------
  3333. WINCRYPT32API
  3334. HCRYPTMSG
  3335. WINAPI
  3336. CryptMsgOpenToDecode(
  3337.     IN DWORD dwMsgEncodingType,
  3338.     IN DWORD dwFlags,
  3339.     IN DWORD dwMsgType,
  3340.     IN HCRYPTPROV hCryptProv,
  3341.     IN OPTIONAL PCERT_INFO pRecipientInfo,
  3342.     IN OPTIONAL PCMSG_STREAM_INFO pStreamInfo
  3343.     );
  3344.  
  3345. //+-------------------------------------------------------------------------
  3346. //  Close a cryptographic message handle
  3347. //
  3348. //  LastError is preserved unless FALSE is returned.
  3349. //--------------------------------------------------------------------------
  3350. WINCRYPT32API
  3351. BOOL
  3352. WINAPI
  3353. CryptMsgClose(
  3354.     IN HCRYPTMSG hCryptMsg
  3355.     );
  3356.  
  3357. //+-------------------------------------------------------------------------
  3358. //  Update the content of a cryptographic message. Depending on how the
  3359. //  message was opened, the content is either encoded or decoded.
  3360. //
  3361. //  This function is repetitively called to append to the message content.
  3362. //  fFinal is set to identify the last update. On fFinal, the encode/decode
  3363. //  is completed. The encoded/decoded content and the decoded parameters
  3364. //  are valid until the open and all duplicated handles are closed.
  3365. //--------------------------------------------------------------------------
  3366. WINCRYPT32API
  3367. BOOL
  3368. WINAPI
  3369. CryptMsgUpdate(
  3370.     IN HCRYPTMSG hCryptMsg,
  3371.     IN const BYTE *pbData,
  3372.     IN DWORD cbData,
  3373.     IN BOOL fFinal
  3374.     );
  3375.  
  3376. //+-------------------------------------------------------------------------
  3377. //  Perform a special "control" function after the final CryptMsgUpdate of a
  3378. //  encoded/decoded cryptographic message.
  3379. //
  3380. //  The dwCtrlType parameter specifies the type of operation to be performed.
  3381. //
  3382. //  The pvCtrlPara definition depends on the dwCtrlType value.
  3383. //
  3384. //  See below for a list of the control operations and their pvCtrlPara
  3385. //  type definition.
  3386. //--------------------------------------------------------------------------
  3387. WINCRYPT32API
  3388. BOOL
  3389. WINAPI
  3390. CryptMsgControl(
  3391.     IN HCRYPTMSG hCryptMsg,
  3392.     IN DWORD dwFlags,
  3393.     IN DWORD dwCtrlType,
  3394.     IN void const *pvCtrlPara
  3395.     );
  3396.  
  3397. //+-------------------------------------------------------------------------
  3398. //  Message control types
  3399. //--------------------------------------------------------------------------
  3400. #define CMSG_CTRL_VERIFY_SIGNATURE       1
  3401. #define CMSG_CTRL_DECRYPT                2
  3402. #define CMSG_CTRL_VERIFY_HASH            5
  3403. #define CMSG_CTRL_ADD_SIGNER             6
  3404. #define CMSG_CTRL_DEL_SIGNER             7
  3405. #define CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR 8
  3406. #define CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR 9
  3407. #define CMSG_CTRL_ADD_CERT               10
  3408. #define CMSG_CTRL_DEL_CERT               11
  3409. #define CMSG_CTRL_ADD_CRL                12
  3410. #define CMSG_CTRL_DEL_CRL                13
  3411.  
  3412. //+-------------------------------------------------------------------------
  3413. //  CMSG_CTRL_VERIFY_SIGNATURE
  3414. //
  3415. //  Verify the signature of a SIGNED or SIGNED_AND_ENVELOPED
  3416. //  message after it has been decoded.
  3417. //
  3418. //  For a SIGNED_AND_ENVELOPED message, called after
  3419. //  CryptMsgControl(CMSG_CTRL_DECRYPT), if CryptMsgOpenToDecode was called
  3420. //  with a NULL pRecipientInfo.
  3421. //
  3422. //  pvCtrlPara points to a CERT_INFO struct.
  3423. //
  3424. //  The CERT_INFO contains the Issuer and SerialNumber identifying
  3425. //  the Signer of the message. The CERT_INFO also contains the
  3426. //  PublicKeyInfo
  3427. //  used to verify the signature. The cryptographic provider specified
  3428. //  in CryptMsgOpenToDecode is used.
  3429. //--------------------------------------------------------------------------
  3430.  
  3431. //+-------------------------------------------------------------------------
  3432. //  CMSG_CTRL_DECRYPT
  3433. //
  3434. //  Decrypt an ENVELOPED or SIGNED_AND_ENVELOPED message after it has been
  3435. //  decoded.
  3436. //
  3437. //  hCryptProv and dwKeySpec specify the private key to use. For dwKeySpec ==
  3438. //  0, defaults to AT_KEYEXCHANGE.
  3439. //
  3440. //  dwRecipientIndex is the index of the recipient in the message associated
  3441. //  with the hCryptProv's private key.
  3442. //
  3443. //  This control function needs to be called, if you don't know the appropriate
  3444. //  recipient before calling CryptMsgOpenToDecode. After the final
  3445. //  CryptMsgUpdate, the list of recipients is obtained by iterating through
  3446. //  CMSG_RECIPIENT_INFO_PARAM. The recipient corresponding to a private
  3447. //  key owned by the caller is selected and passed to this function to decrypt
  3448. //  the message.
  3449. //
  3450. //  Note, the message can only be decrypted once.
  3451. //--------------------------------------------------------------------------
  3452. typedef struct _CMSG_CTRL_DECRYPT_PARA {
  3453.     DWORD       cbSize;
  3454.     HCRYPTPROV  hCryptProv;
  3455.     DWORD       dwKeySpec;
  3456.     DWORD       dwRecipientIndex;
  3457. } CMSG_CTRL_DECRYPT_PARA, *PCMSG_CTRL_DECRYPT_PARA;
  3458.  
  3459.  
  3460. //+-------------------------------------------------------------------------
  3461. //  CMSG_CTRL_VERIFY_HASH
  3462. //
  3463. //  Verify the hash of a HASHED message after it has been decoded.
  3464. //
  3465. //  Only the hCryptMsg parameter is used, to specify the message whose
  3466. //  hash is being verified.
  3467. //--------------------------------------------------------------------------
  3468.  
  3469. //+-------------------------------------------------------------------------
  3470. //  CMSG_CTRL_ADD_SIGNER
  3471. //
  3472. //  Add a signer to a signed-data or signed-and-enveloped-data message.
  3473. //
  3474. //  pvCtrlPara points to a CMSG_SIGNER_ENCODE_INFO.
  3475. //--------------------------------------------------------------------------
  3476.  
  3477. //+-------------------------------------------------------------------------
  3478. //  CMSG_CTRL_DEL_SIGNER
  3479. //
  3480. //  Remove a signer from a signed-data or signed-and-enveloped-data message.
  3481. //
  3482. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  3483. //  signer to be removed.
  3484. //--------------------------------------------------------------------------
  3485.  
  3486. //+-------------------------------------------------------------------------
  3487. //  CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR
  3488. //
  3489. //  Add an unauthenticated attribute to the SignerInfo of a signed-data or
  3490. //  signed-and-enveloped-data message.
  3491. //
  3492. //  The unauthenticated attribute is input in the form of an encoded blob.
  3493. //--------------------------------------------------------------------------
  3494.  
  3495. typedef struct _CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA {
  3496.     DWORD               cbSize;
  3497.     DWORD               dwSignerIndex;
  3498.     CRYPT_DATA_BLOB     blob;
  3499. } CMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_ADD_SIGNER_UNAUTH_ATTR_PARA;
  3500.  
  3501. //+-------------------------------------------------------------------------
  3502. //  CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR
  3503. //
  3504. //  Delete an unauthenticated attribute from the SignerInfo of a signed-data
  3505. //  or signed-and-enveloped-data message.
  3506. //
  3507. //  The unauthenticated attribute to be removed is specified by
  3508. //  a 0-based index.
  3509. //--------------------------------------------------------------------------
  3510.  
  3511. typedef struct _CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA {
  3512.     DWORD               cbSize;
  3513.     DWORD               dwSignerIndex;
  3514.     DWORD               dwUnauthAttrIndex;
  3515. } CMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA, *PCMSG_CTRL_DEL_SIGNER_UNAUTH_ATTR_PARA;
  3516.  
  3517. //+-------------------------------------------------------------------------
  3518. //  CMSG_CTRL_ADD_CERT
  3519. //
  3520. //  Add a certificate to a signed-data or signed-and-enveloped-data message.
  3521. //
  3522. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the certificate's
  3523. //  encoded bytes.
  3524. //--------------------------------------------------------------------------
  3525.  
  3526. //+-------------------------------------------------------------------------
  3527. //  CMSG_CTRL_DEL_CERT
  3528. //
  3529. //  Delete a certificate from a signed-data or signed-and-enveloped-data
  3530. //  message.
  3531. //
  3532. //  pvCtrlPara points to a DWORD containing the 0-based index of the
  3533. //  certificate to be removed.
  3534. //--------------------------------------------------------------------------
  3535.  
  3536. //+-------------------------------------------------------------------------
  3537. //  CMSG_CTRL_ADD_CRL
  3538. //
  3539. //  Add a CRL to a signed-data or signed-and-enveloped-data message.
  3540. //
  3541. //  pvCtrlPara points to a CRYPT_DATA_BLOB containing the CRL's
  3542. //  encoded bytes.
  3543. //--------------------------------------------------------------------------
  3544.  
  3545. //+-------------------------------------------------------------------------
  3546. //  CMSG_CTRL_DEL_CRL
  3547. //
  3548. //  Delete a CRL from a signed-data or signed-and-enveloped-data message.
  3549. //
  3550. //  pvCtrlPara points to a DWORD containing the 0-based index of the CRL
  3551. //  to be removed.
  3552. //--------------------------------------------------------------------------
  3553.  
  3554.  
  3555. //+-------------------------------------------------------------------------
  3556. //  Verify a countersignature, at the SignerInfo level.
  3557. //  ie. verify that pbSignerInfoCountersignature contains the encrypted
  3558. //  hash of the encryptedDigest field of pbSignerInfo.
  3559. //
  3560. //  hCryptProv is used to hash the encryptedDigest field of pbSignerInfo.
  3561. //  The only fields referenced from pciCountersigner are SerialNumber, Issuer,
  3562. //  and SubjectPublicKeyInfo.
  3563. //--------------------------------------------------------------------------
  3564. BOOL
  3565. WINAPI
  3566. CryptMsgVerifyCountersignatureEncoded(
  3567.     IN HCRYPTPROV   hCryptProv,
  3568.     IN DWORD        dwEncodingType,
  3569.     IN PBYTE        pbSignerInfo,
  3570.     IN DWORD        cbSignerInfo,
  3571.     IN PBYTE        pbSignerInfoCountersignature,
  3572.     IN DWORD        cbSignerInfoCountersignature,
  3573.     IN PCERT_INFO   pciCountersigner
  3574.     );
  3575.  
  3576. //+-------------------------------------------------------------------------
  3577. //  Countersign an already-existing signature in a message
  3578. //
  3579. //  dwIndex is a zero-based index of the SignerInfo to be countersigned.
  3580. //--------------------------------------------------------------------------
  3581. BOOL
  3582. WINAPI
  3583. CryptMsgCountersign(
  3584.     IN OUT HCRYPTMSG            hCryptMsg,
  3585.     IN DWORD                    dwIndex,
  3586.     IN DWORD                    cCountersigners,
  3587.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners
  3588.     );
  3589.  
  3590. //+-------------------------------------------------------------------------
  3591. //  Countersign an already-existing signature (encoded SignerInfo).
  3592. //  Output an encoded SignerInfo blob, suitable for use as a countersignature
  3593. //  attribute in the unauthenticated attributes of a signed-data or
  3594. //  signed-and-enveloped-data message.
  3595. //--------------------------------------------------------------------------
  3596. BOOL
  3597. WINAPI
  3598. CryptMsgCountersignEncoded(
  3599.     IN DWORD                    dwEncodingType,
  3600.     IN PBYTE                    pbSignerInfo,
  3601.     IN DWORD                    cbSignerInfo,
  3602.     IN DWORD                    cCountersigners,
  3603.     IN PCMSG_SIGNER_ENCODE_INFO rgCountersigners,
  3604.     OUT PBYTE                   pbCountersignature,
  3605.     IN OUT PDWORD               pcbCountersignature
  3606.     );
  3607.  
  3608.  
  3609. //+-------------------------------------------------------------------------
  3610. //  Get a parameter after encoding/decoding a cryptographic message. Called
  3611. //  after the final CryptMsgUpdate. Only the CMSG_CONTENT_PARAM and
  3612. //  CMSG_COMPUTED_HASH_PARAM are valid for an encoded message.
  3613. //
  3614. //  For an encoded HASHED message, the CMSG_COMPUTED_HASH_PARAM can be got
  3615. //  before any CryptMsgUpdates to get its length.
  3616. //
  3617. //  The pvData type definition depends on the dwParamType value.
  3618. //
  3619. //  Elements pointed to by fields in the pvData structure follow the
  3620. //  structure. Therefore, *pcbData may exceed the size of the structure.
  3621. //
  3622. //  Upon input, if *pcbData == 0, then, *pcbData is updated with the length
  3623. //  of the data and the pvData parameter is ignored.
  3624. //
  3625. //  Upon return, *pcbData is updated with the length of the data.
  3626. //
  3627. //  The OBJID BLOBs returned in the pvData structures point to
  3628. //  their still encoded representation. The appropriate functions
  3629. //  must be called to decode the information.
  3630. //
  3631. //  See below for a list of the parameters to get.
  3632. //--------------------------------------------------------------------------
  3633. WINCRYPT32API
  3634. BOOL
  3635. WINAPI
  3636. CryptMsgGetParam(
  3637.     IN HCRYPTMSG hCryptMsg,
  3638.     IN DWORD dwParamType,
  3639.     IN DWORD dwIndex,
  3640.     OUT void *pvData,
  3641.     IN OUT DWORD *pcbData
  3642.     );
  3643.  
  3644. //+-------------------------------------------------------------------------
  3645. //  Get parameter types and their corresponding data structure definitions.
  3646. //--------------------------------------------------------------------------
  3647. #define CMSG_TYPE_PARAM                              1
  3648. #define CMSG_CONTENT_PARAM                           2
  3649. #define CMSG_BARE_CONTENT_PARAM                      3
  3650. #define CMSG_INNER_CONTENT_TYPE_PARAM                4
  3651. #define CMSG_SIGNER_COUNT_PARAM                      5
  3652. #define CMSG_SIGNER_INFO_PARAM                       6
  3653. #define CMSG_SIGNER_CERT_INFO_PARAM                  7
  3654. #define CMSG_SIGNER_HASH_ALGORITHM_PARAM             8
  3655. #define CMSG_SIGNER_AUTH_ATTR_PARAM                  9
  3656. #define CMSG_SIGNER_UNAUTH_ATTR_PARAM                10
  3657. #define CMSG_CERT_COUNT_PARAM                        11
  3658. #define CMSG_CERT_PARAM                              12
  3659. #define CMSG_CRL_COUNT_PARAM                         13
  3660. #define CMSG_CRL_PARAM                               14
  3661. #define CMSG_ENVELOPE_ALGORITHM_PARAM                15
  3662. #define CMSG_RECIPIENT_COUNT_PARAM                   17
  3663. #define CMSG_RECIPIENT_INDEX_PARAM                   18
  3664. #define CMSG_RECIPIENT_INFO_PARAM                    19
  3665. #define CMSG_HASH_ALGORITHM_PARAM                    20
  3666. #define CMSG_HASH_DATA_PARAM                         21
  3667. #define CMSG_COMPUTED_HASH_PARAM                     22
  3668. #define CMSG_ENCRYPT_PARAM                           26
  3669. #define CMSG_ENCRYPTED_DIGEST                        27
  3670. #define CMSG_ENCODED_SIGNER                          28
  3671. #define CMSG_ENCODED_MESSAGE                         29
  3672.  
  3673. //+-------------------------------------------------------------------------
  3674. //  CMSG_TYPE_PARAM
  3675. //
  3676. //  The type of the decoded message.
  3677. //
  3678. //  pvData points to a DWORD
  3679. //--------------------------------------------------------------------------
  3680.  
  3681. //+-------------------------------------------------------------------------
  3682. //  CMSG_CONTENT_PARAM
  3683. //
  3684. //  The encoded content of a cryptographic message. Depending on how the
  3685. //  message was opened, the content is either the whole PKCS#7
  3686. //  message (opened to encode) or the inner content (opened to decode).
  3687. //  In the decode case, the decrypted content is returned, if enveloped.
  3688. //  If not enveloped, and if the inner content is of type DATA, the returned
  3689. //  data is the contents octets of the inner content.
  3690. //
  3691. //  pvData points to the buffer receiving the content bytes
  3692. //--------------------------------------------------------------------------
  3693.  
  3694. //+-------------------------------------------------------------------------
  3695. //  CMSG_BARE_CONTENT_PARAM
  3696. //
  3697. //  The encoded content of an encoded cryptographic message, without the
  3698. //  outer layer of ContentInfo. That is, only the encoding of the
  3699. //  ContentInfo.content field is returned.
  3700. //
  3701. //  pvData points to the buffer receiving the content bytes
  3702. //--------------------------------------------------------------------------
  3703.  
  3704. //+-------------------------------------------------------------------------
  3705. //  CMSG_INNER_CONTENT_TYPE_PARAM
  3706. //
  3707. //  The type of the inner content of a decoded cryptographic message,
  3708. //  in the form of a NULL-terminated object identifier string
  3709. //  (eg. "1.2.840.113549.1.7.1").
  3710. //
  3711. //  pvData points to the buffer receiving the object identifier string
  3712. //--------------------------------------------------------------------------
  3713.  
  3714. //+-------------------------------------------------------------------------
  3715. //  CMSG_SIGNER_COUNT_PARAM
  3716. //
  3717. //  Count of signers in a SIGNED or SIGNED_AND_ENVELOPED message
  3718. //
  3719. //  pvData points to a DWORD
  3720. //--------------------------------------------------------------------------
  3721.  
  3722. //+-------------------------------------------------------------------------
  3723. //  CMSG_SIGNER_CERT_INFO_PARAM
  3724. //
  3725. //  To get all the signers, repetitively call CryptMsgGetParam, with
  3726. //  dwIndex set to 0 .. SignerCount - 1.
  3727. //
  3728. //  pvData points to a CERT_INFO struct.
  3729. //
  3730. //  Only the following fields have been updated in the CERT_INFO struct:
  3731. //  Issuer and SerialNumber.
  3732. //--------------------------------------------------------------------------
  3733.  
  3734. //+-------------------------------------------------------------------------
  3735. //  CMSG_SIGNER_INFO_PARAM
  3736. //
  3737. //  To get all the signers, repetitively call CryptMsgGetParam, with
  3738. //  dwIndex set to 0 .. SignerCount - 1.
  3739. //
  3740. //  pvData points to a CMSG_SIGNER_INFO struct.
  3741. //--------------------------------------------------------------------------
  3742. typedef struct _CMSG_SIGNER_INFO {
  3743.     DWORD                       dwVersion;
  3744.     CERT_NAME_BLOB              Issuer;
  3745.     CRYPT_INTEGER_BLOB          SerialNumber;
  3746.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  3747.     CRYPT_ALGORITHM_IDENTIFIER  HashEncryptionAlgorithm;
  3748.     CRYPT_DATA_BLOB             EncryptedHash;
  3749.     CRYPT_ATTRIBUTES            AuthAttrs;
  3750.     CRYPT_ATTRIBUTES            UnauthAttrs;
  3751. } CMSG_SIGNER_INFO, *PCMSG_SIGNER_INFO;
  3752.  
  3753. //+-------------------------------------------------------------------------
  3754. //  CMSG_SIGNER_HASH_ALGORITHM_PARAM
  3755. //
  3756. //  This parameter specifies the HashAlgorithm that was used for the signer.
  3757. //
  3758. //  Set dwIndex to iterate through all the signers.
  3759. //
  3760. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3761. //--------------------------------------------------------------------------
  3762.  
  3763. //+-------------------------------------------------------------------------
  3764. //  CMSG_SIGNER_AUTH_ATTR_PARAM
  3765. //
  3766. //  The authenticated attributes for the signer.
  3767. //
  3768. //  Set dwIndex to iterate through all the signers.
  3769. //
  3770. //  pvData points to a CMSG_ATTR struct.
  3771. //--------------------------------------------------------------------------
  3772. typedef CRYPT_ATTRIBUTES CMSG_ATTR;
  3773. typedef CRYPT_ATTRIBUTES *PCMSG_ATTR;
  3774.  
  3775. //+-------------------------------------------------------------------------
  3776. //  CMSG_SIGNER_UNAUTH_ATTR_PARAM
  3777. //
  3778. //  The unauthenticated attributes for the signer.
  3779. //
  3780. //  Set dwIndex to iterate through all the signers.
  3781. //
  3782. //  pvData points to a CMSG_ATTR struct.
  3783. //--------------------------------------------------------------------------
  3784.  
  3785. //+-------------------------------------------------------------------------
  3786. //  CMSG_CERT_COUNT_PARAM
  3787. //
  3788. //  Count of certificates in a SIGNED or SIGNED_AND_ENVELOPED message.
  3789. //
  3790. //  pvData points to a DWORD
  3791. //--------------------------------------------------------------------------
  3792.  
  3793. //+-------------------------------------------------------------------------
  3794. //  CMSG_CERT_PARAM
  3795. //
  3796. //  To get all the certificates, repetitively call CryptMsgGetParam, with
  3797. //  dwIndex set to 0 .. CertCount - 1.
  3798. //
  3799. //  pvData points to an array of the certificate's encoded bytes.
  3800. //--------------------------------------------------------------------------
  3801.  
  3802. //+-------------------------------------------------------------------------
  3803. //  CMSG_CRL_COUNT_PARAM
  3804. //
  3805. //  Count of CRLs in a SIGNED or SIGNED_AND_ENVELOPED message.
  3806. //
  3807. //  pvData points to a DWORD
  3808. //--------------------------------------------------------------------------
  3809.  
  3810. //+-------------------------------------------------------------------------
  3811. //  CMSG_CRL_PARAM
  3812. //
  3813. //  To get all the CRLs, repetitively call CryptMsgGetParam, with
  3814. //  dwIndex set to 0 .. CrlCount - 1.
  3815. //
  3816. //  pvData points to an array of the CRL's encoded bytes.
  3817. //--------------------------------------------------------------------------
  3818.  
  3819.  
  3820. //+-------------------------------------------------------------------------
  3821. //  CMSG_ENVELOPE_ALGORITHM_PARAM
  3822. //
  3823. //  The ContentEncryptionAlgorithm that was used in
  3824. //  an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3825. //
  3826. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3827. //--------------------------------------------------------------------------
  3828.  
  3829. //+-------------------------------------------------------------------------
  3830. //  CMSG_RECIPIENT_COUNT_PARAM
  3831. //
  3832. //  Count of recipients in an ENVELOPED or SIGNED_AND_ENVELOPED message.
  3833. //
  3834. //  pvData points to a DWORD
  3835. //--------------------------------------------------------------------------
  3836.  
  3837. //+-------------------------------------------------------------------------
  3838. //  CMSG_RECIPIENT_INDEX_PARAM
  3839. //
  3840. //  Index of the recipient used to decrypt an ENVELOPED or SIGNED_AND_ENVELOPED
  3841. //  message.
  3842. //
  3843. //  pvData points to a DWORD
  3844. //--------------------------------------------------------------------------
  3845.  
  3846. //+-------------------------------------------------------------------------
  3847. //  CMSG_RECIPIENT_INFO_PARAM
  3848. //
  3849. //  To get all the recipients, repetitively call CryptMsgGetParam, with
  3850. //  dwIndex set to 0 .. RecipientCount - 1.
  3851. //
  3852. //  pvData points to a CERT_INFO struct.
  3853. //
  3854. //  Only the following fields have been updated in the CERT_INFO struct:
  3855. //  Issuer, SerialNumber and PublicKeyAlgorithm. The PublicKeyAlgorithm
  3856. //  specifies the KeyEncryptionAlgorithm that was used.
  3857. //--------------------------------------------------------------------------
  3858.  
  3859. //+-------------------------------------------------------------------------
  3860. //  CMSG_HASH_ALGORITHM_PARAM
  3861. //
  3862. //  The HashAlgorithm in a HASHED message.
  3863. //
  3864. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3865. //--------------------------------------------------------------------------
  3866.  
  3867. //+-------------------------------------------------------------------------
  3868. //  CMSG_HASH_DATA_PARAM
  3869. //
  3870. //  The hash in a HASHED message.
  3871. //
  3872. //  pvData points to an array of bytes.
  3873. //--------------------------------------------------------------------------
  3874.  
  3875. //+-------------------------------------------------------------------------
  3876. //  CMSG_COMPUTED_HASH_PARAM
  3877. //
  3878. //  The computed hash for a HASHED message.
  3879. //
  3880. //  This may be called for either an encoded or decoded message.
  3881. //  It also may be called before any encoded CryptMsgUpdates to get its length.
  3882. //
  3883. //  pvData points to an array of bytes.
  3884. //--------------------------------------------------------------------------
  3885.  
  3886. //+-------------------------------------------------------------------------
  3887. //  CMSG_ENCRYPT_PARAM
  3888. //
  3889. //  The ContentEncryptionAlgorithm that was used in an ENCRYPTED message.
  3890. //
  3891. //  pvData points to an CRYPT_ALGORITHM_IDENTIFIER struct.
  3892. //--------------------------------------------------------------------------
  3893.  
  3894. //+-------------------------------------------------------------------------
  3895. //  CMSG_ENCODED_MESSAGE
  3896. //
  3897. //  The full encoded message. This is useful in the case of a decoded
  3898. //  message which has been modified (eg. a signed-data or
  3899. //  signed-and-enveloped-data message which has been countersigned).
  3900. //
  3901. //  pvData points to an array of the message's encoded bytes.
  3902. //--------------------------------------------------------------------------
  3903.  
  3904. //+-------------------------------------------------------------------------
  3905. //  CryptMsg OID installable functions
  3906. //--------------------------------------------------------------------------
  3907.  
  3908. // If *phCryptProv is NULL upon entry, then, if supported, the installable
  3909. // function should acquire a default provider and return. Note, its up
  3910. // to the installable function to release at process detach.
  3911. #define CMSG_OID_GEN_ENCRYPT_KEY_FUNC   "CryptMsgDllGenEncryptKey"
  3912. typedef BOOL (WINAPI *PFN_CMSG_GEN_ENCRYPT_KEY) (
  3913.     IN OUT HCRYPTPROV               *phCryptProv,
  3914.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  3915.     IN PVOID                        pvEncryptAuxInfo,
  3916.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  3917.     OUT HCRYPTKEY                   *phEncryptKey
  3918.     );
  3919.  
  3920. #define CMSG_OID_EXPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllExportEncryptKey"
  3921. typedef BOOL (WINAPI *PFN_CMSG_EXPORT_ENCRYPT_KEY) (
  3922.     IN HCRYPTPROV                   hCryptProv,
  3923.     IN HCRYPTKEY                    hEncryptKey,
  3924.     IN PCERT_PUBLIC_KEY_INFO        pPublicKeyInfo,
  3925.     OUT PBYTE                       pbData,
  3926.     IN OUT PDWORD                   pcbData
  3927.     );
  3928.  
  3929. #define CMSG_OID_IMPORT_ENCRYPT_KEY_FUNC   "CryptMsgDllImportEncryptKey"
  3930. typedef BOOL (WINAPI *PFN_CMSG_IMPORT_ENCRYPT_KEY) (
  3931.     IN HCRYPTPROV                   hCryptProv,
  3932.     IN DWORD                        dwKeySpec,
  3933.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiEncrypt,
  3934.     IN PCRYPT_ALGORITHM_IDENTIFIER  paiPubKey,
  3935.     IN PBYTE                        pbEncodedKey,
  3936.     IN DWORD                        cbEncodedKey,
  3937.     OUT HCRYPTKEY                   *phEncryptKey
  3938.     );
  3939.  
  3940.  
  3941. //+=========================================================================
  3942. //  Certificate Store Data Structures and APIs
  3943. //==========================================================================
  3944.  
  3945. //+-------------------------------------------------------------------------
  3946. //              In its most basic implementation, a cert store is simply a
  3947. //              collection of certificates and/or CRLs. This is the case when
  3948. //              a cert store is opened with all of its certificates and CRLs
  3949. //              coming from a PKCS #7 encoded cryptographic message.
  3950. //
  3951. //              Nonetheless, all cert stores have the following properties:
  3952. //               - A public key may have more than one certificate in the store.
  3953. //                 For example, a private/public key used for signing may have a
  3954. //                 certificate issued for VISA and another issued for
  3955. //                 Mastercard. Also, when a certificate is renewed there might
  3956. //                 be more than one certificate with the same subject and
  3957. //                 issuer.
  3958. //               - However, each certificate in the store is uniquely
  3959. //                 identified by its Issuer and SerialNumber.
  3960. //               - There's an issuer of subject certificate relationship. A
  3961. //                 certificate's issuer is found by doing a match of
  3962. //                 pSubjectCert->Issuer with pIssuerCert->Subject.
  3963. //                 The relationship is verified by using
  3964. //                 the issuer's public key to verify the subject certificate's
  3965. //                 signature. Note, there might be X.509 v3 extensions
  3966. //                 to assist in finding the issuer certificate.
  3967. //               - Since issuer certificates might be renewed, a subject
  3968. //                 certificate might have more than one issuer certificate.
  3969. //               - There's an issuer of CRL relationship. An
  3970. //                 issuer's CRL is found by doing a match of
  3971. //                 pIssuerCert->Subject with pCrl->Issuer.
  3972. //                 The relationship is verified by using
  3973. //                 the issuer's public key to verify the CRL's
  3974. //                 signature. Note, there might be X.509 v3 extensions
  3975. //                 to assist in finding the CRL.
  3976. //               - Since some issuers might support the X.509 v3 delta CRL
  3977. //                 extensions, an issuer might have more than one CRL.
  3978. //               - The store shouldn't have any redundant certificates or
  3979. //                 CRLs. There shouldn't be two certificates with the same
  3980. //                 Issuer and SerialNumber. There shouldn't be two CRLs with
  3981. //                 the same Issuer, ThisUpdate and NextUpdate.
  3982. //               - The store has NO policy or trust information. No
  3983. //                 certificates are tagged as being "root". Its up to
  3984. //                 the application to maintain a list of CertIds (Issuer +
  3985. //                 SerialNumber) for certificates it trusts.
  3986. //               - The store might contain bad certificates and/or CRLs.
  3987. //                 The issuer's signature of a subject certificate or CRL may
  3988. //                 not verify. Certificates or CRLs may not satisfy their
  3989. //                 time validity requirements. Certificates may be
  3990. //                 revoked.
  3991. //
  3992. //              In addition to the certificates and CRLs, properties can be
  3993. //              stored. There are two predefined property IDs for a user
  3994. //              certificate: CERT_KEY_PROV_HANDLE_PROP_ID and
  3995. //              CERT_KEY_PROV_INFO_PROP_ID. The CERT_KEY_PROV_HANDLE_PROP_ID
  3996. //              is a HCRYPTPROV handle to the private key assoicated
  3997. //              with the certificate. The CERT_KEY_PROV_INFO_PROP_ID contains
  3998. //              information to be used to call
  3999. //              CryptAcquireContext and CryptProvSetParam to get a handle
  4000. //              to the private key associated with the certificate.
  4001. //
  4002. //              There exists two more predefined property IDs for certificates
  4003. //              and CRLs, CERT_SHA1_HASH_PROP_ID and CERT_MD5_HASH_PROP_ID.
  4004. //              If these properties don't already exist, then, a hash of the
  4005. //              content is computed. (CERT_HASH_PROP_ID maps to the default
  4006. //              hash algorithm, currently, CERT_SHA1_HASH_PROP_ID).
  4007. //
  4008. //              There are additional APIs for creating certificate and CRL
  4009. //      contexts not in a store (CertCreateCertificateContext and
  4010. //      CertCreateCRLContext).
  4011. //
  4012. //--------------------------------------------------------------------------
  4013.  
  4014.  
  4015. typedef void *HCERTSTORE;
  4016.  
  4017. //+-------------------------------------------------------------------------
  4018. //  Certificate context.
  4019. //
  4020. //  A certificate context contains both the encoded and decoded representation
  4021. //  of a certificate. A certificate context returned by a cert store function
  4022. //  must be freed by calling the CertFreeCertificateContext function. The
  4023. //  CertDuplicateCertificateContext function can be called to make a duplicate
  4024. //  copy (which also must be freed by calling CertFreeCertificateContext).
  4025. //--------------------------------------------------------------------------
  4026. typedef struct _CERT_CONTEXT {
  4027.     DWORD                   dwCertEncodingType;
  4028.     BYTE                    *pbCertEncoded;
  4029.     DWORD                   cbCertEncoded;
  4030.     PCERT_INFO              pCertInfo;
  4031.     HCERTSTORE              hCertStore;
  4032. } CERT_CONTEXT, *PCERT_CONTEXT;
  4033. typedef const CERT_CONTEXT *PCCERT_CONTEXT;
  4034.  
  4035. //+-------------------------------------------------------------------------
  4036. //  CRL context.
  4037. //
  4038. //  A CRL context contains both the encoded and decoded representation
  4039. //  of a CRL. A CRL context returned by a cert store function
  4040. //  must be freed by calling the CertFreeCRLContext function. The
  4041. //  CertDuplicateCRLContext function can be called to make a duplicate
  4042. //  copy (which also must be freed by calling CertFreeCRLContext).
  4043. //--------------------------------------------------------------------------
  4044. typedef struct _CRL_CONTEXT {
  4045.     DWORD                   dwCertEncodingType;
  4046.     BYTE                    *pbCrlEncoded;
  4047.     DWORD                   cbCrlEncoded;
  4048.     PCRL_INFO               pCrlInfo;
  4049.     HCERTSTORE              hCertStore;
  4050. } CRL_CONTEXT, *PCRL_CONTEXT;
  4051. typedef const CRL_CONTEXT *PCCRL_CONTEXT;
  4052.  
  4053. //+-------------------------------------------------------------------------
  4054. //  Certificate Trust List (CTL) context.
  4055. //
  4056. //  A CTL context contains both the encoded and decoded representation
  4057. //  of a CTL. Also contains an opened HCRYPTMSG handle to the decoded
  4058. //  cryptographic signed message containing the CTL_INFO as its inner content.
  4059. //  pbCtlContent is the encoded inner content of the signed message.
  4060. //
  4061. //  The CryptMsg APIs can be used to extract additional signer information.
  4062. //--------------------------------------------------------------------------
  4063. typedef struct _CTL_CONTEXT {
  4064.     DWORD                   dwMsgAndCertEncodingType;
  4065.     BYTE                    *pbCtlEncoded;
  4066.     DWORD                   cbCtlEncoded;
  4067.     PCTL_INFO               pCtlInfo;
  4068.     HCERTSTORE              hCertStore;
  4069.     HCRYPTMSG               hCryptMsg;
  4070.     BYTE                    *pbCtlContent;
  4071.     DWORD                   cbCtlContent;
  4072. } CTL_CONTEXT, *PCTL_CONTEXT;
  4073. typedef const CTL_CONTEXT *PCCTL_CONTEXT;
  4074.  
  4075. //+-------------------------------------------------------------------------
  4076. //  Certificate, CRL and CTL property IDs
  4077. //
  4078. //  See CertSetCertificateContextProperty or CertGetCertificateContextProperty
  4079. //  for usage information.
  4080. //--------------------------------------------------------------------------
  4081. #define CERT_KEY_PROV_HANDLE_PROP_ID        1
  4082. #define CERT_KEY_PROV_INFO_PROP_ID          2
  4083. #define CERT_SHA1_HASH_PROP_ID              3
  4084. #define CERT_MD5_HASH_PROP_ID               4
  4085. #define CERT_HASH_PROP_ID                   CERT_SHA1_HASH_PROP_ID
  4086. #define CERT_KEY_CONTEXT_PROP_ID            5
  4087. #define CERT_KEY_SPEC_PROP_ID               6
  4088. #define CERT_IE30_RESERVED_PROP_ID          7
  4089. #define CERT_PUBKEY_HASH_RESERVED_PROP_ID   8
  4090. #define CERT_ENHKEY_USAGE_PROP_ID           9
  4091. #define CERT_CTL_USAGE_PROP_ID              CERT_ENHKEY_USAGE_PROP_ID
  4092. #define CERT_NEXT_UPDATE_LOCATION_PROP_ID   10
  4093. #define CERT_FRIENDLY_NAME_PROP_ID          11
  4094. #define CERT_PVK_FILE_PROP_ID                12
  4095. // Note, 32 - 34 are reserved for the CERT, CRL and CTL file element IDs.
  4096. #define CERT_FIRST_RESERVED_PROP_ID         13
  4097.  
  4098. #define CERT_LAST_RESERVED_PROP_ID          0x00007FFF
  4099. #define CERT_FIRST_USER_PROP_ID             0x00008000
  4100. #define CERT_LAST_USER_PROP_ID              0x0000FFFF
  4101.  
  4102.  
  4103. #define IS_CERT_HASH_PROP_ID(X)     (CERT_SHA1_HASH_PROP_ID == (X) || \
  4104.                                             CERT_MD5_HASH_PROP_ID == (X))
  4105.  
  4106.  
  4107. //+-------------------------------------------------------------------------
  4108. //  Cryptographic Key Provider Information
  4109. //
  4110. //  CRYPT_KEY_PROV_INFO defines the CERT_KEY_PROV_INFO_PROP_ID's pvData.
  4111. //
  4112. //  The CRYPT_KEY_PROV_INFO fields are passed to CryptAcquireContext
  4113. //  to get a HCRYPTPROV handle. The optional CRYPT_KEY_PROV_PARAM fields are
  4114. //  passed to CryptProvSetParam to further initialize the provider.
  4115. //
  4116. //  The dwKeySpec field identifies the private key to use from the container
  4117. //  For example, AT_KEYEXCHANGE or AT_SIGNATURE.
  4118. //--------------------------------------------------------------------------
  4119. typedef struct _CRYPT_KEY_PROV_PARAM {
  4120.     DWORD           dwParam;
  4121.     BYTE            *pbData;
  4122.     DWORD           cbData;
  4123.     DWORD           dwFlags;
  4124. } CRYPT_KEY_PROV_PARAM, *PCRYPT_KEY_PROV_PARAM;
  4125.  
  4126. typedef struct _CRYPT_KEY_PROV_INFO {
  4127.     LPWSTR                  pwszContainerName;
  4128.     LPWSTR                  pwszProvName;
  4129.     DWORD                   dwProvType;
  4130.     DWORD                   dwFlags;
  4131.     DWORD                   cProvParam;
  4132.     PCRYPT_KEY_PROV_PARAM   rgProvParam;
  4133.     DWORD                   dwKeySpec;
  4134. } CRYPT_KEY_PROV_INFO, *PCRYPT_KEY_PROV_INFO;
  4135.  
  4136. //+-------------------------------------------------------------------------
  4137. //  The following flag should be set in the above dwFlags to enable
  4138. //  a CertSetCertificateContextProperty(CERT_KEY_CONTEXT_PROP_ID) after a
  4139. //  CryptAcquireContext is done in the Sign or Decrypt Message functions.
  4140. //
  4141. //  The following define must not collide with any of the
  4142. //  CryptAcquireContext dwFlag defines.
  4143. //--------------------------------------------------------------------------
  4144. #define CERT_SET_KEY_PROV_HANDLE_PROP_ID    0x00000001
  4145. #define CERT_SET_KEY_CONTEXT_PROP_ID        0x00000001
  4146.  
  4147. //+-------------------------------------------------------------------------
  4148. //  Certificate Key Context
  4149. //
  4150. //  CERT_KEY_CONTEXT defines the CERT_KEY_CONTEXT_PROP_ID's pvData.
  4151. //--------------------------------------------------------------------------
  4152. typedef struct _CERT_KEY_CONTEXT {
  4153.     DWORD           cbSize;           // sizeof(CERT_KEY_CONTEXT)
  4154.     HCRYPTPROV      hCryptProv;
  4155.     DWORD           dwKeySpec;
  4156. } CERT_KEY_CONTEXT, *PCERT_KEY_CONTEXT;
  4157.  
  4158. //+-------------------------------------------------------------------------
  4159. //  Certificate Store Provider Types
  4160. //--------------------------------------------------------------------------
  4161. #define CERT_STORE_PROV_MSG                 ((LPCSTR) 1)
  4162. #define CERT_STORE_PROV_MEMORY              ((LPCSTR) 2)
  4163. #define CERT_STORE_PROV_FILE                ((LPCSTR) 3)
  4164. #define CERT_STORE_PROV_REG                 ((LPCSTR) 4)
  4165.  
  4166. #define CERT_STORE_PROV_PKCS7               ((LPCSTR) 5)
  4167. #define CERT_STORE_PROV_SERIALIZED          ((LPCSTR) 6)
  4168. #define CERT_STORE_PROV_FILENAME_A          ((LPCSTR) 7)
  4169. #define CERT_STORE_PROV_FILENAME_W          ((LPCSTR) 8)
  4170. #define CERT_STORE_PROV_FILENAME            CERT_STORE_PROV_FILENAME_W
  4171. #define CERT_STORE_PROV_SYSTEM_A            ((LPCSTR) 9)
  4172. #define CERT_STORE_PROV_SYSTEM_W            ((LPCSTR) 10)
  4173. #define CERT_STORE_PROV_SYSTEM              CERT_STORE_PROV_SYSTEM_W
  4174.  
  4175. #define sz_CERT_STORE_PROV_MEMORY           "Memory"
  4176. #define sz_CERT_STORE_PROV_FILENAME_W       "File"
  4177. #define sz_CERT_STORE_PROV_FILENAME         sz_CERT_STORE_PROV_FILENAME_W
  4178. #define sz_CERT_STORE_PROV_SYSTEM_W         "System"
  4179. #define sz_CERT_STORE_PROV_SYSTEM           sz_CERT_STORE_PROV_SYSTEM_W
  4180. #define sz_CERT_STORE_PROV_PKCS7            "PKCS7"
  4181. #define sz_CERT_STORE_PROV_SERIALIZED       "Serialized"
  4182.  
  4183. //+-------------------------------------------------------------------------
  4184. //  Certificate Store verify/results flags
  4185. //--------------------------------------------------------------------------
  4186. #define CERT_STORE_SIGNATURE_FLAG           0x00000001
  4187. #define CERT_STORE_TIME_VALIDITY_FLAG       0x00000002
  4188. #define CERT_STORE_REVOCATION_FLAG          0x00000004
  4189. #define CERT_STORE_NO_CRL_FLAG              0x00010000
  4190. #define CERT_STORE_NO_ISSUER_FLAG           0x00020000
  4191.  
  4192.  
  4193. //+-------------------------------------------------------------------------
  4194. //  Certificate Store open/property flags
  4195. //--------------------------------------------------------------------------
  4196. #define CERT_STORE_NO_CRYPT_RELEASE_FLAG        0x00000001
  4197. #define CERT_STORE_READONLY_FLAG                0x00008000
  4198.  
  4199. //+-------------------------------------------------------------------------
  4200. //  Certificate Store Provider flags are in the HiWord (0xFFFF0000)
  4201. //--------------------------------------------------------------------------
  4202.  
  4203. //+-------------------------------------------------------------------------
  4204. //  Certificate System Store Flag Values
  4205. //--------------------------------------------------------------------------
  4206. // Location of the system store in the registry:
  4207. //  HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
  4208. #define CERT_SYSTEM_STORE_LOCATION_MASK         0x00030000
  4209. #define CERT_SYSTEM_STORE_CURRENT_USER          0x00010000
  4210. #define CERT_SYSTEM_STORE_LOCAL_MACHINE         0x00020000
  4211.  
  4212.  
  4213. //+-------------------------------------------------------------------------
  4214. //  Open the cert store using the specified store provider.
  4215. //
  4216. //  hCryptProv specifies the crypto provider to use to create the hash
  4217. //  properties or verify the signature of a subject certificate or CRL.
  4218. //  The store doesn't need to use a private
  4219. //  key. If the CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, hCryptProv is
  4220. //  CryptReleaseContext'ed on the final CertCloseStore.
  4221. //
  4222. //  Note, if the open fails, hCryptProv is released if it would have been
  4223. //  released when the store was closed.
  4224. //
  4225. //  If hCryptProv is zero, then, the default provider and container for the
  4226. //  PROV_RSA_FULL provider type is CryptAcquireContext'ed with
  4227. //  CRYPT_VERIFYCONTEXT access. The CryptAcquireContext is deferred until
  4228. //  the first create hash or verify signature. In addition, once acquired,
  4229. //  the default provider isn't released until process exit when crypt32.dll
  4230. //  is unloaded. The acquired default provider is shared across all stores
  4231. //  and threads.
  4232. //
  4233. //  After initializing the store's data structures and optionally acquiring a
  4234. //  default crypt provider, CertOpenStore calls CryptGetOIDFunctionAddress to
  4235. //  get the address of the CRYPT_OID_OPEN_STORE_PROV_FUNC specified by
  4236. //  lpszStoreProvider. Since a store can contain certificates with different
  4237. //  encoding types, CryptGetOIDFunctionAddress is called with dwEncodingType
  4238. //  set to 0 and not the dwEncodingType passed to CertOpenStore.
  4239. //  PFN_CERT_DLL_OPEN_STORE_FUNC specifies the signature of the provider's
  4240. //  open function. This provider open function is called to load the
  4241. //  store's certificates and CRLs. Optionally, the provider may return an
  4242. //  array of functions called before a certificate or CRL is added or deleted
  4243. //  or has a property that is set.
  4244. //
  4245. //  Use of the dwEncodingType parameter is provider dependent. The type
  4246. //  definition for pvPara also depends on the provider.
  4247. //
  4248. //  Store providers are installed or registered via
  4249. //  CryptInstallOIDFunctionAddress or CryptRegisterOIDFunction, where,
  4250. //  dwEncodingType is 0 and pszFuncName is CRYPT_OID_OPEN_STORE_PROV_FUNC.
  4251. //
  4252. //  Here's a list of the predefined provider types (implemented in crypt32.dll):
  4253. //
  4254. //  CERT_STORE_PROV_MSG:
  4255. //      Gets the certificates and CRLs from the specified cryptographic message.
  4256. //      dwEncodingType contains the message and certificate encoding types.
  4257. //      The message's handle is passed in pvPara. Given,
  4258. //          HCRYPTMSG hCryptMsg; pvPara = (const void *) hCryptMsg;
  4259. //
  4260. //  CERT_STORE_PROV_MEMORY
  4261. //  sz_CERT_STORE_PROV_MEMORY:
  4262. //      Opens a store without any initial certificates or CRLs. pvPara
  4263. //      isn't used.
  4264. //
  4265. //  CERT_STORE_PROV_FILE:
  4266. //      Reads the certificates and CRLs from the specified file. The file's
  4267. //      handle is passed in pvPara. Given,
  4268. //          HANDLE hFile; pvPara = (const void *) hFile;
  4269. //
  4270. //      For a successful open, the file pointer is advanced past
  4271. //      the certificates and CRLs and their properties read from the file.
  4272. //      Note, only expects a serialized store and not a file containing
  4273. //      either a PKCS #7 signed message or a single encoded certificate.
  4274. //
  4275. //      The hFile isn't closed.
  4276. //
  4277. //  CERT_STORE_PROV_REG:
  4278. //      Reads the certificates and CRLs from the registry. The registry's
  4279. //      key handle is passed in pvPara. Given,
  4280. //          HKEY hKey; pvPara = (const void *) hKey;
  4281. //
  4282. //      The input hKey isn't closed by the provider. Before returning, the
  4283. //      provider opens/creates "Certificates" and "CRLs" subkeys. These
  4284. //      subkeys remain open until the store is closed.
  4285. //
  4286. //      If CERT_STORE_READONLY_FLAG is set, then, the registry subkeys are
  4287. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry subkeys
  4288. //      are RegCreateKey'ed with KEY_ALL_ACCESS.
  4289. //
  4290. //      This provider returns the array of functions for reading, writing,
  4291. //      deleting and property setting certificates and CRLs.
  4292. //      Any changes to the opened store are immediately pushed through to
  4293. //      the registry. However, if CERT_STORE_READONLY_FLAG is set, then,
  4294. //      writing, deleting or property setting results in a
  4295. //      SetLastError(E_ACCESSDENIED).
  4296. //
  4297. //      Note, all the certificates and CRLs are read from the registry
  4298. //      when the store is opened. The opened store serves as a write through
  4299. //      cache. However, the opened store isn't notified of other changes
  4300. //      made to the registry. Note, RegNotifyChangeKeyValue is supported
  4301. //      on NT but not supported on Windows95.
  4302. //
  4303. //  CERT_STORE_PROV_PKCS7:
  4304. //  sz_CERT_STORE_PROV_PKCS7:
  4305. //      Gets the certificates and CRLs from the encoded PKCS #7 signed message.
  4306. //      dwEncodingType specifies the message and certificate encoding types.
  4307. //      The pointer to the encoded message's blob is passed in pvPara. Given,
  4308. //          CRYPT_DATA_BLOB EncodedMsg; pvPara = (const void *) &EncodedMsg;
  4309. //
  4310. //      Note, also supports the IE3.0 special version of a
  4311. //      PKCS #7 signed message referred to as a "SPC" formatted message.
  4312. //
  4313. //  CERT_STORE_PROV_SERIALIZED:
  4314. //  sz_CERT_STORE_PROV_SERIALIZED:
  4315. //      Gets the certificates and CRLs from memory containing a serialized
  4316. //      store.  The pointer to the serialized memory blob is passed in pvPara.
  4317. //      Given,
  4318. //          CRYPT_DATA_BLOB Serialized; pvPara = (const void *) &Serialized;
  4319. //
  4320. //  CERT_STORE_PROV_FILENAME_A:
  4321. //  CERT_STORE_PROV_FILENAME_W:
  4322. //  CERT_STORE_PROV_FILENAME:
  4323. //  sz_CERT_STORE_PROV_FILENAME_W:
  4324. //  sz_CERT_STORE_PROV_FILENAME:
  4325. //      Opens the file and first attempts to read as a serialized store. Then,
  4326. //      as a PKCS #7 signed message. Finally, as a single encoded certificate.
  4327. //      The filename is passed in pvPara. The filename is UNICODE for the
  4328. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  4329. //          LPCWSTR pwszFilename; pvPara = (const void *) pwszFilename;
  4330. //      For "_A": given,
  4331. //          LPCSTR pszFilename; pvPara = (const void *) pszFilename;
  4332. //
  4333. //      Note, the default (without "_A" or "_W") is unicode.
  4334. //
  4335. //      Note, also supports the reading of the IE3.0 special version of a
  4336. //      PKCS #7 signed message file referred to as a "SPC" formatted file.
  4337. //
  4338. //  CERT_STORE_PROV_SYSTEM_A:
  4339. //  CERT_STORE_PROV_SYSTEM_W:
  4340. //  CERT_STORE_PROV_SYSTEM:
  4341. //  sz_CERT_STORE_PROV_SYSTEM_W:
  4342. //  sz_CERT_STORE_PROV_SYSTEM:
  4343. //      Opens the specified "system" store. Currently, all the system
  4344. //      stores are stored in the registry. The upper word of the dwFlags
  4345. //      parameter is used to specify the location of the system store. It
  4346. //      should be set to either CERT_SYSTEM_STORE_CURRENT_USER for
  4347. //      HKEY_CURRENT_USER or CERT_SYSTEM_STORE_LOCAL_MACHINE for
  4348. //      HKEY_LOCAL_MACHINE.
  4349. //
  4350. //      After opening the registry key associated with the system name,
  4351. //      the CERT_STORE_PROV_REG provider is called to complete the open.
  4352. //
  4353. //      The system store name is passed in pvPara. The name is UNICODE for the
  4354. //      "_W" provider and ASCII for the "_A" provider. For "_W": given,
  4355. //          LPCWSTR pwszSystemName; pvPara = (const void *) pwszSystemName;
  4356. //      For "_A": given,
  4357. //          LPCSTR pszSystemName; pvPara = (const void *) pszSystemName;
  4358. //
  4359. //      Note, the default (without "_A" or "_W") is UNICODE.
  4360. //
  4361. //      If CERT_STORE_READONLY_FLAG is set, then, the registry is
  4362. //      RegOpenKey'ed with KEY_READ_ACCESS. Otherwise, the registry is
  4363. //      RegCreateKey'ed with KEY_ALL_ACCESS.
  4364. //
  4365. //      The "root" store is treated differently from the other system
  4366. //      stores. Before a certificate is added to or deleted from the "root"
  4367. //      store, a pop up message box is displayed. The certificate's subject,
  4368. //      issuer, serial number, time validity, sha1 and md5 thumbprints are
  4369. //      displayed. The user is given the option to do the add or delete.
  4370. //      If they don't allow the operation, LastError is set to E_ACCESSDENIED.
  4371. //--------------------------------------------------------------------------
  4372. WINCRYPT32API
  4373. HCERTSTORE
  4374. WINAPI
  4375. CertOpenStore(
  4376.     IN LPCSTR lpszStoreProvider,
  4377.     IN DWORD dwEncodingType,
  4378.     IN HCRYPTPROV hCryptProv,
  4379.     IN DWORD dwFlags,
  4380.     IN const void *pvPara
  4381.     );
  4382.  
  4383.  
  4384. //+-------------------------------------------------------------------------
  4385. //  OID Installable Certificate Store Provider Data Structures
  4386. //--------------------------------------------------------------------------
  4387.  
  4388. // Handle returned by the store provider when opened.
  4389. typedef void *HCERTSTOREPROV;
  4390.  
  4391. // Store Provider OID function's pszFuncName.
  4392. #define CRYPT_OID_OPEN_STORE_PROV_FUNC   "CertDllOpenStoreProv"
  4393.  
  4394. // Note, the Store Provider OID function's dwEncodingType is always 0.
  4395.  
  4396. // The following information is returned by the provider when opened. Its
  4397. // zeroed with cbSize set before the provider is called. If the provider
  4398. // doesn't need to be called again after the open it doesn't need to
  4399. // make any updates to the CERT_STORE_PROV_INFO.
  4400. typedef struct _CERT_STORE_PROV_INFO {
  4401.     DWORD               cbSize;
  4402.     DWORD               cStoreProvFunc;
  4403.     void                **rgpvStoreProvFunc;
  4404.     HCERTSTOREPROV      hStoreProv;
  4405.     DWORD               dwStoreProvFlags;
  4406. } CERT_STORE_PROV_INFO, *PCERT_STORE_PROV_INFO;
  4407.  
  4408. // Definition of the store provider's open function.
  4409. //
  4410. // *pStoreProvInfo has been zeroed before the call.
  4411. //
  4412. // Note, pStoreProvInfo->cStoreProvFunc should be set last.  Once set,
  4413. // all subsequent store calls, such as CertAddSerializedElementToStore will
  4414. // call the appropriate provider callback function.
  4415. typedef BOOL (WINAPI *PFN_CERT_DLL_OPEN_STORE_PROV_FUNC)(
  4416.         IN LPCSTR lpszStoreProvider,
  4417.         IN DWORD dwEncodingType,
  4418.         IN HCRYPTPROV hCryptProv,
  4419.         IN DWORD dwFlags,
  4420.         IN const void *pvPara,
  4421.         IN HCERTSTORE hCertStore,
  4422.         IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  4423.         );
  4424.  
  4425. // Indices into the store provider's array of callback functions.
  4426. //
  4427. // The provider can implement any subset of the following functions. It
  4428. // sets pStoreProvInfo->cStoreProvFunc to the last index + 1 and any
  4429. // preceding not implemented functions to NULL.
  4430. #define CERT_STORE_PROV_CLOSE_FUNC              0
  4431. #define CERT_STORE_PROV_READ_CERT_FUNC          1
  4432. #define CERT_STORE_PROV_WRITE_CERT_FUNC         2
  4433. #define CERT_STORE_PROV_DELETE_CERT_FUNC        3
  4434. #define CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC  4
  4435. #define CERT_STORE_PROV_READ_CRL_FUNC           5
  4436. #define CERT_STORE_PROV_WRITE_CRL_FUNC          6
  4437. #define CERT_STORE_PROV_DELETE_CRL_FUNC         7
  4438. #define CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC   8
  4439. #define CERT_STORE_PROV_READ_CTL_FUNC           9
  4440. #define CERT_STORE_PROV_WRITE_CTL_FUNC          10
  4441. #define CERT_STORE_PROV_DELETE_CTL_FUNC         11
  4442. #define CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC   12
  4443.  
  4444. // Called by CertCloseStore when the store's reference count is
  4445. // decremented to 0.
  4446. typedef void (WINAPI *PFN_CERT_STORE_PROV_CLOSE)(
  4447.         IN HCERTSTOREPROV hStoreProv,
  4448.         IN DWORD dwFlags
  4449.         );
  4450.  
  4451. // Currently not called directly by the store APIs. However, may be exported
  4452. // to support other providers based on it.
  4453. //
  4454. // Reads the provider's copy of the certificate context. If it exists,
  4455. // creates a new certificate context.
  4456. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CERT)(
  4457.         IN HCERTSTOREPROV hStoreProv,
  4458.         IN PCCERT_CONTEXT pStoreCertContext,
  4459.         IN DWORD dwFlags,
  4460.         OUT PCCERT_CONTEXT *ppProvCertContext
  4461.         );
  4462.  
  4463. #define CERT_STORE_PROV_WRITE_ADD_FLAG      0x1
  4464.  
  4465. // Called by CertAddEncodedCertificateToStore,
  4466. // CertAddCertificateContextToStore or CertAddSerializedElementToStore before
  4467. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4468. // addition to the encoded certificate, the added pCertContext might also
  4469. // have properties.
  4470. //
  4471. // Returns TRUE if its OK to update the the store.
  4472. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CERT)(
  4473.         IN HCERTSTOREPROV hStoreProv,
  4474.         IN PCCERT_CONTEXT pCertContext,
  4475.         IN DWORD dwFlags
  4476.         );
  4477.  
  4478. // Called by CertDeleteCertificateFromStore before deleting from the
  4479. // store.
  4480. //
  4481. // Returns TRUE if its OK to delete from the store.
  4482. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CERT)(
  4483.         IN HCERTSTOREPROV hStoreProv,
  4484.         IN PCCERT_CONTEXT pCertContext,
  4485.         IN DWORD dwFlags
  4486.         );
  4487.  
  4488. // Called by CertSetCertificateContextProperty before setting the
  4489. // certificate's property. Also called by CertGetCertificateContextProperty,
  4490. // when getting a hash property that needs to be created and then persisted
  4491. // via the set.
  4492. //
  4493. // Upon input, the property hasn't been set for the pCertContext parameter.
  4494. //
  4495. // Returns TRUE if its OK to set the property.
  4496. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CERT_PROPERTY)(
  4497.         IN HCERTSTOREPROV hStoreProv,
  4498.         IN PCCERT_CONTEXT pCertContext,
  4499.         IN DWORD dwPropId,
  4500.         IN DWORD dwFlags,
  4501.         IN const void *pvData
  4502.         );
  4503.  
  4504. // Currently not called directly by the store APIs. However, may be exported
  4505. // to support other providers based on it.
  4506. //
  4507. // Reads the provider's copy of the CRL context. If it exists,
  4508. // creates a new CRL context.
  4509. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CRL)(
  4510.         IN HCERTSTOREPROV hStoreProv,
  4511.         IN PCCRL_CONTEXT pStoreCrlContext,
  4512.         IN DWORD dwFlags,
  4513.         OUT PCCRL_CONTEXT *ppProvCrlContext
  4514.         );
  4515.  
  4516. // Called by CertAddEncodedCRLToStore,
  4517. // CertAddCRLContextToStore or CertAddSerializedElementToStore before
  4518. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4519. // addition to the encoded CRL, the added pCertContext might also
  4520. // have properties.
  4521. //
  4522. // Returns TRUE if its OK to update the the store.
  4523. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CRL)(
  4524.         IN HCERTSTOREPROV hStoreProv,
  4525.         IN PCCRL_CONTEXT pCrlContext,
  4526.         IN DWORD dwFlags
  4527.         );
  4528.  
  4529. // Called by CertDeleteCRLFromStore before deleting from the store.
  4530. //
  4531. // Returns TRUE if its OK to delete from the store.
  4532. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CRL)(
  4533.         IN HCERTSTOREPROV hStoreProv,
  4534.         IN PCCRL_CONTEXT pCrlContext,
  4535.         IN DWORD dwFlags
  4536.         );
  4537.  
  4538. // Called by CertSetCRLContextProperty before setting the
  4539. // CRL's property. Also called by CertGetCRLContextProperty,
  4540. // when getting a hash property that needs to be created and then persisted
  4541. // via the set.
  4542. //
  4543. // Upon input, the property hasn't been set for the pCrlContext parameter.
  4544. //
  4545. // Returns TRUE if its OK to set the property.
  4546. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CRL_PROPERTY)(
  4547.         IN HCERTSTOREPROV hStoreProv,
  4548.         IN PCCRL_CONTEXT pCrlContext,
  4549.         IN DWORD dwPropId,
  4550.         IN DWORD dwFlags,
  4551.         IN const void *pvData
  4552.         );
  4553.  
  4554. // Currently not called directly by the store APIs. However, may be exported
  4555. // to support other providers based on it.
  4556. //
  4557. // Reads the provider's copy of the CTL context. If it exists,
  4558. // creates a new CTL context.
  4559. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_READ_CTL)(
  4560.         IN HCERTSTOREPROV hStoreProv,
  4561.         IN PCCTL_CONTEXT pStoreCtlContext,
  4562.         IN DWORD dwFlags,
  4563.         OUT PCCTL_CONTEXT *ppProvCtlContext
  4564.         );
  4565.  
  4566. // Called by CertAddEncodedCTLToStore,
  4567. // CertAddCTLContextToStore or CertAddSerializedElementToStore before
  4568. // adding to the store. The CERT_STORE_PROV_WRITE_ADD_FLAG is set. In
  4569. // addition to the encoded CTL, the added pCertContext might also
  4570. // have properties.
  4571. //
  4572. // Returns TRUE if its OK to update the the store.
  4573. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_WRITE_CTL)(
  4574.         IN HCERTSTOREPROV hStoreProv,
  4575.         IN PCCTL_CONTEXT pCtlContext,
  4576.         IN DWORD dwFlags
  4577.         );
  4578.  
  4579. // Called by CertDeleteCTLFromStore before deleting from the store.
  4580. //
  4581. // Returns TRUE if its OK to delete from the store.
  4582. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_DELETE_CTL)(
  4583.         IN HCERTSTOREPROV hStoreProv,
  4584.         IN PCCTL_CONTEXT pCtlContext,
  4585.         IN DWORD dwFlags
  4586.         );
  4587.  
  4588. // Called by CertSetCTLContextProperty before setting the
  4589. // CTL's property. Also called by CertGetCTLContextProperty,
  4590. // when getting a hash property that needs to be created and then persisted
  4591. // via the set.
  4592. //
  4593. // Upon input, the property hasn't been set for the pCtlContext parameter.
  4594. //
  4595. // Returns TRUE if its OK to set the property.
  4596. typedef BOOL (WINAPI *PFN_CERT_STORE_PROV_SET_CTL_PROPERTY)(
  4597.         IN HCERTSTOREPROV hStoreProv,
  4598.         IN PCCTL_CONTEXT pCtlContext,
  4599.         IN DWORD dwPropId,
  4600.         IN DWORD dwFlags,
  4601.         IN const void *pvData
  4602.         );
  4603.  
  4604. //+-------------------------------------------------------------------------
  4605. //  Duplicate a cert store handle
  4606. //--------------------------------------------------------------------------
  4607. WINCRYPT32API
  4608. HCERTSTORE
  4609. WINAPI
  4610. CertDuplicateStore(
  4611.     IN HCERTSTORE hCertStore
  4612.     );
  4613.  
  4614. #define CERT_STORE_SAVE_AS_STORE        1
  4615. #define CERT_STORE_SAVE_AS_PKCS7        2
  4616.  
  4617. #define CERT_STORE_SAVE_TO_FILE         1
  4618. #define CERT_STORE_SAVE_TO_MEMORY       2
  4619. #define CERT_STORE_SAVE_TO_FILENAME_A   3
  4620. #define CERT_STORE_SAVE_TO_FILENAME_W   4
  4621. #define CERT_STORE_SAVE_TO_FILENAME     CERT_STORE_SAVE_TO_FILENAME_W
  4622.  
  4623. //+-------------------------------------------------------------------------
  4624. //  Save the cert store. Extended version with lots of options.
  4625. //
  4626. //  According to the dwSaveAs parameter, the store can be saved as a
  4627. //  serialized store (CERT_STORE_SAVE_AS_STORE) containing properties in
  4628. //  addition to encoded certificates, CRLs and CTLs or the store can be saved
  4629. //  as a PKCS #7 signed message (CERT_STORE_SAVE_AS_PKCS7) which doesn't
  4630. //  include the properties or CTLs.
  4631. //
  4632. //  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  4633. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't saved into
  4634. //  a serialized store.
  4635. //
  4636. //  For CERT_STORE_SAVE_AS_PKCS7, the dwEncodingType specifies the message
  4637. //  encoding type. The dwEncodingType parameter isn't used for
  4638. //  CERT_STORE_SAVE_AS_STORE.
  4639. //
  4640. //  The dwFlags parameter currently isn't used and should be set to 0.
  4641. //
  4642. //  The dwSaveTo and pvSaveToPara parameters specify where to save the
  4643. //  store as follows:
  4644. //    CERT_STORE_SAVE_TO_FILE:
  4645. //      Saves to the specified file. The file's handle is passed in
  4646. //      pvSaveToPara. Given,
  4647. //          HANDLE hFile; pvSaveToPara = (void *) hFile;
  4648. //
  4649. //      For a successful save, the file pointer is positioned after the
  4650. //      last write.
  4651. //
  4652. //    CERT_STORE_SAVE_TO_MEMORY:
  4653. //      Saves to the specified memory blob. The pointer to
  4654. //      the memory blob is passed in pvSaveToPara. Given,
  4655. //          CRYPT_DATA_BLOB SaveBlob; pvSaveToPara = (void *) &SaveBlob;
  4656. //      Upon entry, the SaveBlob's pbData and cbData need to be initialized.
  4657. //      Upon return, cbData is updated with the actual length.
  4658. //      For a length only calculation, pbData should be set to NULL. If
  4659. //      pbData is non-NULL and cbData isn't large enough, FALSE is returned
  4660. //      with a last error of ERRROR_MORE_DATA.
  4661. //
  4662. //    CERT_STORE_SAVE_TO_FILENAME_A:
  4663. //    CERT_STORE_SAVE_TO_FILENAME_W:
  4664. //    CERT_STORE_SAVE_TO_FILENAME:
  4665. //      Opens the file and saves to it. The filename is passed in pvSaveToPara.
  4666. //      The filename is UNICODE for the "_W" option and ASCII for the "_A"
  4667. //      option. For "_W": given,
  4668. //          LPCWSTR pwszFilename; pvSaveToPara = (void *) pwszFilename;
  4669. //      For "_A": given,
  4670. //          LPCSTR pszFilename; pvSaveToPara = (void *) pszFilename;
  4671. //
  4672. //      Note, the default (without "_A" or "_W") is UNICODE.
  4673. //
  4674. //--------------------------------------------------------------------------
  4675. BOOL
  4676. WINAPI
  4677. CertSaveStore(
  4678.     IN HCERTSTORE hCertStore,
  4679.     IN DWORD dwEncodingType,
  4680.     IN DWORD dwSaveAs,
  4681.     IN DWORD dwSaveTo,
  4682.     IN OUT void *pvSaveToPara,
  4683.     IN DWORD dwFlags
  4684.     );
  4685.  
  4686. //+-------------------------------------------------------------------------
  4687. //  Certificate Store close flags
  4688. //--------------------------------------------------------------------------
  4689. #define CERT_CLOSE_STORE_FORCE_FLAG         0x00000001
  4690. #define CERT_CLOSE_STORE_CHECK_FLAG         0x00000002
  4691.  
  4692. //+-------------------------------------------------------------------------
  4693. //  Close a cert store handle.
  4694. //
  4695. //  There needs to be a corresponding close for each open and duplicate.
  4696. //
  4697. //  Even on the final close, the cert store isn't freed until all of its
  4698. //  certificate and CRL contexts have also been freed.
  4699. //
  4700. //  On the final close, the hCryptProv passed to CertStoreOpen is
  4701. //  CryptReleaseContext'ed.
  4702. //
  4703. //  To force the closure of the store with all of its memory freed, set the
  4704. //  CERT_STORE_CLOSE_FORCE_FLAG. This flag should be set when the caller does
  4705. //  its own reference counting and wants everything to vanish.
  4706. //
  4707. //  To check if all the store's certificates and CRLs have been freed and that
  4708. //  this is the last CertCloseStore, set the CERT_CLOSE_STORE_CHECK_FLAG. If
  4709. //  set and certs, CRLs or stores still need to be freed/closed, FALSE is
  4710. //  returned with LastError set to CRYPT_E_PENDING_CLOSE. Note, for FALSE,
  4711. //  the store is still closed. This is a diagnostic flag.
  4712. //
  4713. //  LastError is preserved unless CERT_CLOSE_STORE_CHECK_FLAG is set and FALSE
  4714. //  is returned.
  4715. //--------------------------------------------------------------------------
  4716. WINCRYPT32API
  4717. BOOL
  4718. WINAPI
  4719. CertCloseStore(
  4720.     IN HCERTSTORE hCertStore,
  4721.     DWORD dwFlags
  4722.     );
  4723.  
  4724. //+-------------------------------------------------------------------------
  4725. //  Get the subject certificate context uniquely identified by its Issuer and
  4726. //  SerialNumber from the store.
  4727. //
  4728. //  If the certificate isn't found, NULL is returned. Otherwise, a pointer to
  4729. //  a read only CERT_CONTEXT is returned. CERT_CONTEXT must be freed by calling
  4730. //  CertFreeCertificateContext. CertDuplicateCertificateContext can be called to make a
  4731. //  duplicate.
  4732. //
  4733. //  The returned certificate might not be valid. Normally, it would be
  4734. //  verified when getting its issuer certificate (CertGetIssuerCertificateFromStore).
  4735. //--------------------------------------------------------------------------
  4736. WINCRYPT32API
  4737. PCCERT_CONTEXT
  4738. WINAPI
  4739. CertGetSubjectCertificateFromStore(
  4740.     IN HCERTSTORE hCertStore,
  4741.     IN DWORD dwCertEncodingType,
  4742.     IN PCERT_INFO pCertId           // Only the Issuer and SerialNumber
  4743.                                     // fields are used
  4744.     );
  4745.  
  4746. //+-------------------------------------------------------------------------
  4747. //  Enumerate the certificate contexts in the store.
  4748. //
  4749. //  If a certificate isn't found, NULL is returned.
  4750. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4751. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4752. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4753. //  can be called to make a duplicate.
  4754. //
  4755. //  pPrevCertContext MUST BE NULL to enumerate the first
  4756. //  certificate in the store. Successive certificates are enumerated by setting
  4757. //  pPrevCertContext to the CERT_CONTEXT returned by a previous call.
  4758. //
  4759. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4760. //  this function, even for an error.
  4761. //--------------------------------------------------------------------------
  4762. WINCRYPT32API
  4763. PCCERT_CONTEXT
  4764. WINAPI
  4765. CertEnumCertificatesInStore(
  4766.     IN HCERTSTORE hCertStore,
  4767.     IN PCCERT_CONTEXT pPrevCertContext
  4768.     );
  4769.  
  4770. //+-------------------------------------------------------------------------
  4771. //  Find the first or next certificate context in the store.
  4772. //
  4773. //  The certificate is found according to the dwFindType and its pvFindPara.
  4774. //  See below for a list of the find types and its parameters.
  4775. //
  4776. //  Currently dwFindFlags is only used for CERT_FIND_SUBJECT_ATTR,
  4777. //  CERT_FIND_ISSUER_ATTR or CERT_FIND_CTL_USAGE. Otherwise, must be set to 0.
  4778. //
  4779. //  Usage of dwCertEncodingType depends on the dwFindType.
  4780. //
  4781. //  If the first or next certificate isn't found, NULL is returned.
  4782. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  4783. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  4784. //  pPrevCertContext on a subsequent call. CertDuplicateCertificateContext
  4785. //  can be called to make a duplicate.
  4786. //
  4787. //  pPrevCertContext MUST BE NULL on the first
  4788. //  call to find the certificate. To find the next certificate, the
  4789. //  pPrevCertContext is set to the CERT_CONTEXT returned by a previous call.
  4790. //
  4791. //  NOTE: a NON-NULL pPrevCertContext is always CertFreeCertificateContext'ed by
  4792. //  this function, even for an error.
  4793. //--------------------------------------------------------------------------
  4794. WINCRYPT32API
  4795. PCCERT_CONTEXT
  4796. WINAPI
  4797. CertFindCertificateInStore(
  4798.     IN HCERTSTORE hCertStore,
  4799.     IN DWORD dwCertEncodingType,
  4800.     IN DWORD dwFindFlags,
  4801.     IN DWORD dwFindType,
  4802.     IN const void *pvFindPara,
  4803.     IN PCCERT_CONTEXT pPrevCertContext
  4804.     );
  4805.  
  4806.  
  4807. //+-------------------------------------------------------------------------
  4808. // Certificate comparison functions
  4809. //--------------------------------------------------------------------------
  4810. #define CERT_COMPARE_MASK           0xFFFF
  4811. #define CERT_COMPARE_SHIFT          16
  4812. #define CERT_COMPARE_ANY            0
  4813. #define CERT_COMPARE_SHA1_HASH      1
  4814. #define CERT_COMPARE_NAME           2
  4815. #define CERT_COMPARE_ATTR           3
  4816. #define CERT_COMPARE_MD5_HASH       4
  4817. #define CERT_COMPARE_PROPERTY       5
  4818. #define CERT_COMPARE_PUBLIC_KEY     6
  4819. #define CERT_COMPARE_HASH           CERT_COMPARE_SHA1_HASH
  4820. #define CERT_COMPARE_NAME_STR_A     7
  4821. #define CERT_COMPARE_NAME_STR_W     8
  4822. #define CERT_COMPARE_KEY_SPEC       9
  4823. #define CERT_COMPARE_ENHKEY_USAGE   10
  4824. #define CERT_COMPARE_CTL_USAGE      CERT_COMPARE_ENHKEY_USAGE
  4825.  
  4826. //+-------------------------------------------------------------------------
  4827. //  dwFindType
  4828. //
  4829. //  The dwFindType definition consists of two components:
  4830. //   - comparison function
  4831. //   - certificate information flag
  4832. //--------------------------------------------------------------------------
  4833. #define CERT_FIND_ANY           (CERT_COMPARE_ANY << CERT_COMPARE_SHIFT)
  4834. #define CERT_FIND_SHA1_HASH     (CERT_COMPARE_SHA1_HASH << CERT_COMPARE_SHIFT)
  4835. #define CERT_FIND_MD5_HASH      (CERT_COMPARE_MD5_HASH << CERT_COMPARE_SHIFT)
  4836. #define CERT_FIND_HASH          CERT_FIND_SHA1_HASH
  4837. #define CERT_FIND_PROPERTY      (CERT_COMPARE_PROPERTY << CERT_COMPARE_SHIFT)
  4838. #define CERT_FIND_PUBLIC_KEY    (CERT_COMPARE_PUBLIC_KEY << CERT_COMPARE_SHIFT)
  4839. #define CERT_FIND_SUBJECT_NAME  (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  4840.                                  CERT_INFO_SUBJECT_FLAG)
  4841. #define CERT_FIND_SUBJECT_ATTR  (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  4842.                                  CERT_INFO_SUBJECT_FLAG)
  4843. #define CERT_FIND_ISSUER_NAME   (CERT_COMPARE_NAME << CERT_COMPARE_SHIFT | \
  4844.                                  CERT_INFO_ISSUER_FLAG)
  4845. #define CERT_FIND_ISSUER_ATTR   (CERT_COMPARE_ATTR << CERT_COMPARE_SHIFT | \
  4846.                                  CERT_INFO_ISSUER_FLAG)
  4847. #define CERT_FIND_SUBJECT_STR_A (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  4848.                                  CERT_INFO_SUBJECT_FLAG)
  4849. #define CERT_FIND_SUBJECT_STR_W (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  4850.                                  CERT_INFO_SUBJECT_FLAG)
  4851. #define CERT_FIND_SUBJECT_STR   CERT_FIND_SUBJECT_STR_W
  4852. #define CERT_FIND_ISSUER_STR_A  (CERT_COMPARE_NAME_STR_A << CERT_COMPARE_SHIFT | \
  4853.                                  CERT_INFO_ISSUER_FLAG)
  4854. #define CERT_FIND_ISSUER_STR_W  (CERT_COMPARE_NAME_STR_W << CERT_COMPARE_SHIFT | \
  4855.                                  CERT_INFO_ISSUER_FLAG)
  4856. #define CERT_FIND_ISSUER_STR    CERT_FIND_ISSUER_STR_W
  4857. #define CERT_FIND_KEY_SPEC      (CERT_COMPARE_KEY_SPEC << CERT_COMPARE_SHIFT)
  4858. #define CERT_FIND_ENHKEY_USAGE  (CERT_COMPARE_ENHKEY_USAGE << CERT_COMPARE_SHIFT)
  4859. #define CERT_FIND_CTL_USAGE     CERT_FIND_ENHKEY_USAGE
  4860.  
  4861.  
  4862.  
  4863. //+-------------------------------------------------------------------------
  4864. //  CERT_FIND_ANY
  4865. //
  4866. //  Find any certificate.
  4867. //
  4868. //  pvFindPara isn't used.
  4869. //--------------------------------------------------------------------------
  4870.  
  4871. //+-------------------------------------------------------------------------
  4872. //  CERT_FIND_HASH
  4873. //
  4874. //  Find a certificate with the specified hash.
  4875. //
  4876. //  pvFindPara points to a CRYPT_HASH_BLOB.
  4877. //--------------------------------------------------------------------------
  4878.  
  4879. //+-------------------------------------------------------------------------
  4880. //  CERT_FIND_PROPERTY
  4881. //
  4882. //  Find a certificate having the specified property.
  4883. //
  4884. //  pvFindPara points to a DWORD containing the PROP_ID
  4885. //--------------------------------------------------------------------------
  4886.  
  4887. //+-------------------------------------------------------------------------
  4888. //  CERT_FIND_PUBLIC_KEY
  4889. //
  4890. //  Find a certificate matching the specified public key.
  4891. //
  4892. //  pvFindPara points to a CERT_PUBLIC_KEY_INFO containing the public key
  4893. //--------------------------------------------------------------------------
  4894.  
  4895. //+-------------------------------------------------------------------------
  4896. //  CERT_FIND_SUBJECT_NAME
  4897. //  CERT_FIND_ISSUER_NAME
  4898. //
  4899. //  Find a certificate with the specified subject/issuer name. Does an exact
  4900. //  match of the entire name.
  4901. //
  4902. //  Restricts search to certificates matching the dwCertEncodingType.
  4903. //
  4904. //  pvFindPara points to a CERT_NAME_BLOB.
  4905. //--------------------------------------------------------------------------
  4906.  
  4907. //+-------------------------------------------------------------------------
  4908. //  CERT_FIND_SUBJECT_ATTR
  4909. //  CERT_FIND_ISSUER_ATTR
  4910. //
  4911. //  Find a certificate with the specified subject/issuer attributes.
  4912. //
  4913. //  Compares the attributes in the subject/issuer name with the
  4914. //  Relative Distinguished Name's (CERT_RDN) array of attributes specified in
  4915. //  pvFindPara. The comparison iterates through the CERT_RDN attributes and looks
  4916. //  for an attribute match in any of the subject/issuer's RDNs.
  4917. //
  4918. //  The CERT_RDN_ATTR fields can have the following special values:
  4919. //    pszObjId == NULL              - ignore the attribute object identifier
  4920. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  4921. //    Value.pbData == NULL          - match any value
  4922. //
  4923. //  Currently only an exact, case sensitive match is supported.
  4924. //
  4925. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set in dwFindFlags if the RDN was
  4926. //  initialized with unicode strings as for
  4927. //  CryptEncodeObject(X509_UNICODE_NAME).
  4928. //
  4929. //  Restricts search to certificates matching the dwCertEncodingType.
  4930. //
  4931. //  pvFindPara points to a CERT_RDN (defined in wincert.h).
  4932. //--------------------------------------------------------------------------
  4933.  
  4934. //+-------------------------------------------------------------------------
  4935. //  CERT_FIND_SUBJECT_STR_A
  4936. //  CERT_FIND_SUBJECT_STR_W | CERT_FIND_SUBJECT_STR
  4937. //  CERT_FIND_ISSUER_STR_A
  4938. //  CERT_FIND_ISSUER_STR_W  | CERT_FIND_ISSUER_STR
  4939. //
  4940. //  Find a certificate containing the specified subject/issuer name string.
  4941. //
  4942. //  First, the certificate's subject/issuer is converted to a name string
  4943. //  via CertNameToStrA/CertNameToStrW(CERT_SIMPLE_NAME_STR). Then, a
  4944. //  case insensitive substring within string match is performed.
  4945. //
  4946. //  Restricts search to certificates matching the dwCertEncodingType.
  4947. //
  4948. //  For *_STR_A, pvFindPara points to a null terminated character string.
  4949. //  For *_STR_W, pvFindPara points to a null terminated wide character string.
  4950. //--------------------------------------------------------------------------
  4951.  
  4952. //+-------------------------------------------------------------------------
  4953. //  CERT_FIND_KEY_SPEC
  4954. //
  4955. //  Find a certificate having a CERT_KEY_SPEC_PROP_ID property matching
  4956. //  the specified KeySpec.
  4957. //
  4958. //  pvFindPara points to a DWORD containing the KeySpec.
  4959. //--------------------------------------------------------------------------
  4960.  
  4961. //+-------------------------------------------------------------------------
  4962. //  CERT_FIND_ENHKEY_USAGE
  4963. //
  4964. //  Find a certificate having the szOID_ENHANCED_KEY_USAGE extension or
  4965. //  the CERT_ENHKEY_USAGE_PROP_ID and matching the specified pszUsageIdentifers.
  4966. //
  4967. //  pvFindPara points to a CERT_ENHKEY_USAGE data structure. If pvFindPara
  4968. //  is NULL or CERT_ENHKEY_USAGE's cUsageIdentifier is 0, then, matches any
  4969. //  certificate having enhanced key usage.
  4970. //
  4971. //  The CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG can be set in dwFindFlags to
  4972. //  also match a certificate without either the extension or property.
  4973. //
  4974. //  If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set in dwFindFlags, finds
  4975. //  certificates without the key usage extension or property. Setting this
  4976. //  flag takes precedence over pvFindPara being NULL.
  4977. //
  4978. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only does a match
  4979. //  using the extension. If pvFindPara is NULL or cUsageIdentifier is set to
  4980. //  0, finds certificates having the extension. If
  4981. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4982. //  without the extension. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4983. //  certificates without the extension.
  4984. //
  4985. //  If the CERT_FIND_EXT_PROP_ENHKEY_USAGE_FLAG is set, then, only does a match
  4986. //  using the property. If pvFindPara is NULL or cUsageIdentifier is set to
  4987. //  0, finds certificates having the property. If
  4988. //  CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG is set, also matches a certificate
  4989. //  without the property. If CERT_FIND_NO_ENHKEY_USAGE_FLAG is set, finds
  4990. //  certificates without the property.
  4991. //--------------------------------------------------------------------------
  4992.  
  4993. #define CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG  0x1
  4994. #define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG  0x2
  4995. #define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG 0x4
  4996. #define CERT_FIND_NO_ENHKEY_USAGE_FLAG        0x8
  4997.  
  4998. #define CERT_FIND_OPTIONAL_CTL_USAGE_FLAG   CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG
  4999.  
  5000. #define CERT_FIND_EXT_ONLY_CTL_USAGE_FLAG \
  5001.         CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG
  5002.  
  5003. #define CERT_FIND_PROP_ONLY_CTL_USAGE_FLAG \
  5004.         CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG
  5005.  
  5006. #define CERT_FIND_NO_CTL_USAGE_FLAG         CERT_FIND_NO_ENHKEY_USAGE_FLAG
  5007.  
  5008. //+-------------------------------------------------------------------------
  5009. //  Get the certificate context from the store for the first or next issuer
  5010. //  of the specified subject certificate. Perform the enabled
  5011. //  verification checks on the subject. (Note, the checks are on the subject
  5012. //  using the returned issuer certificate.)
  5013. //
  5014. //  If the first or next issuer certificate isn't found, NULL is returned.
  5015. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned. CERT_CONTEXT
  5016. //  must be freed by calling CertFreeCertificateContext or is freed when passed as the
  5017. //  pPrevIssuerContext on a subsequent call. CertDuplicateCertificateContext
  5018. //  can be called to make a duplicate.
  5019. //
  5020. //  For a self signed subject certificate, NULL is returned with LastError set
  5021. //  to CERT_STORE_SELF_SIGNED. The enabled verification checks are still done.
  5022. //
  5023. //  The pSubjectContext may have been obtained from this store, another store
  5024. //  or created by the caller application. When created by the caller, the
  5025. //  CertCreateCertificateContext function must have been called.
  5026. //
  5027. //  An issuer may have multiple certificates. This may occur when the validity
  5028. //  period is about to change. pPrevIssuerContext MUST BE NULL on the first
  5029. //  call to get the issuer. To get the next certificate for the issuer, the
  5030. //  pPrevIssuerContext is set to the CERT_CONTEXT returned by a previous call.
  5031. //
  5032. //  NOTE: a NON-NULL pPrevIssuerContext is always CertFreeCertificateContext'ed by
  5033. //  this function, even for an error.
  5034. //
  5035. //  The following flags can be set in *pdwFlags to enable verification checks
  5036. //  on the subject certificate context:
  5037. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the returned
  5038. //                                      issuer certificate to verify the
  5039. //                                      signature on the subject certificate.
  5040. //                                      Note, if pSubjectContext->hCertStore ==
  5041. //                                      hCertStore, the store provider might
  5042. //                                      be able to eliminate a redo of
  5043. //                                      the signature verify.
  5044. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  5045. //                                      its within the subject certificate's
  5046. //                                      validity period
  5047. //      CERT_STORE_REVOCATION_FLAG    - check if the subject certificate is on
  5048. //                                      the issuer's revocation list
  5049. //
  5050. //  If an enabled verification check fails, then, its flag is set upon return.
  5051. //  If CERT_STORE_REVOCATION_FLAG was enabled and the issuer doesn't have a
  5052. //  CRL in the store, then, CERT_STORE_NO_CRL_FLAG is set in addition to
  5053. //  the CERT_STORE_REVOCATION_FLAG.
  5054. //
  5055. //  If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, then,
  5056. //  CERT_STORE_NO_ISSUER_FLAG is set if it doesn't have an issuer certificate
  5057. //  in the store.
  5058. //
  5059. //  For a verification check failure, a pointer to the issuer's CERT_CONTEXT
  5060. //  is still returned and SetLastError isn't updated.
  5061. //--------------------------------------------------------------------------
  5062. WINCRYPT32API
  5063. PCCERT_CONTEXT
  5064. WINAPI
  5065. CertGetIssuerCertificateFromStore(
  5066.     IN HCERTSTORE hCertStore,
  5067.     IN PCCERT_CONTEXT pSubjectContext,
  5068.     IN OPTIONAL PCCERT_CONTEXT pPrevIssuerContext,
  5069.     IN OUT DWORD *pdwFlags
  5070.     );
  5071.  
  5072. //+-------------------------------------------------------------------------
  5073. //  Perform the enabled verification checks on the subject certificate
  5074. //  using the issuer. Same checks and flags definitions as for the above
  5075. //  CertGetIssuerCertificateFromStore.
  5076. //
  5077. //  If you are only checking CERT_STORE_TIME_VALIDITY_FLAG, then, the
  5078. //  issuer can be NULL.
  5079. //
  5080. //  For a verification check failure, SUCCESS is still returned.
  5081. //--------------------------------------------------------------------------
  5082. WINCRYPT32API
  5083. BOOL
  5084. WINAPI
  5085. CertVerifySubjectCertificateContext(
  5086.     IN PCCERT_CONTEXT pSubject,
  5087.     IN OPTIONAL PCCERT_CONTEXT pIssuer,
  5088.     IN OUT DWORD *pdwFlags
  5089.     );
  5090.  
  5091. //+-------------------------------------------------------------------------
  5092. //  Duplicate a certificate context
  5093. //--------------------------------------------------------------------------
  5094. WINCRYPT32API
  5095. PCCERT_CONTEXT
  5096. WINAPI
  5097. CertDuplicateCertificateContext(
  5098.     IN PCCERT_CONTEXT pCertContext
  5099.     );
  5100.  
  5101. //+-------------------------------------------------------------------------
  5102. //  Create a certificate context from the encoded certificate. The created
  5103. //  context isn't put in a store.
  5104. //
  5105. //  Makes a copy of the encoded certificate in the created context.
  5106. //
  5107. //  If unable to decode and create the certificate context, NULL is returned.
  5108. //  Otherwise, a pointer to a read only CERT_CONTEXT is returned.
  5109. //  CERT_CONTEXT must be freed by calling CertFreeCertificateContext.
  5110. //  CertDuplicateCertificateContext can be called to make a duplicate.
  5111. //
  5112. //  CertSetCertificateContextProperty and CertGetCertificateContextProperty can be called
  5113. //  to store properties for the certificate.
  5114. //--------------------------------------------------------------------------
  5115. WINCRYPT32API
  5116. PCCERT_CONTEXT
  5117. WINAPI
  5118. CertCreateCertificateContext(
  5119.     IN DWORD dwCertEncodingType,
  5120.     IN const BYTE *pbCertEncoded,
  5121.     IN DWORD cbCertEncoded
  5122.     );
  5123.  
  5124. //+-------------------------------------------------------------------------
  5125. //  Free a certificate context
  5126. //
  5127. //  There needs to be a corresponding free for each context obtained by a
  5128. //  get, find, duplicate or create.
  5129. //--------------------------------------------------------------------------
  5130. WINCRYPT32API
  5131. BOOL
  5132. WINAPI
  5133. CertFreeCertificateContext(
  5134.     IN PCCERT_CONTEXT pCertContext
  5135.     );
  5136.  
  5137. //+-------------------------------------------------------------------------
  5138. //  Set the property for the specified certificate context.
  5139. //
  5140. //  The type definition for pvData depends on the dwPropId value. There are
  5141. //  five predefined types:
  5142. //      CERT_KEY_PROV_HANDLE_PROP_ID - a HCRYPTPROV for the certificate's
  5143. //      private key is passed in pvData. Updates the hCryptProv field
  5144. //      of the CERT_KEY_CONTEXT_PROP_ID. If the CERT_KEY_CONTEXT_PROP_ID
  5145. //      doesn't exist, its created with all the other fields zeroed out. If
  5146. //      CERT_STORE_NO_CRYPT_RELEASE_FLAG isn't set, HCRYPTPROV is implicitly
  5147. //      released when either the property is set to NULL or on the final
  5148. //      free of the CertContext.
  5149. //
  5150. //      CERT_KEY_PROV_INFO_PROP_ID - a PCRYPT_KEY_PROV_INFO for the certificate's
  5151. //      private key is passed in pvData.
  5152. //
  5153. //      CERT_SHA1_HASH_PROP_ID -
  5154. //      CERT_MD5_HASH_PROP_ID  - normally, either property is implicitly
  5155. //      set by doing a CertGetCertificateContextProperty. pvData points to a
  5156. //      CRYPT_HASH_BLOB.
  5157. //
  5158. //      CERT_KEY_CONTEXT_PROP_ID - a PCERT_KEY_CONTEXT for the certificate's
  5159. //      private key is passed in pvData. The CERT_KEY_CONTEXT contains both the
  5160. //      hCryptProv and dwKeySpec for the private key.
  5161. //      See the CERT_KEY_PROV_HANDLE_PROP_ID for more information about
  5162. //      the hCryptProv field and dwFlags settings. Note, more fields may
  5163. //      be added for this property. The cbSize field value will be adjusted
  5164. //      accordingly.
  5165. //
  5166. //      CERT_KEY_SPEC_PROP_ID - the dwKeySpec for the private key. pvData
  5167. //      points to a DWORD containing the KeySpec
  5168. //
  5169. //      CERT_ENHKEY_USAGE_PROP_ID - enhanced key usage definition for the
  5170. //      certificate. pvData points to a CRYPT_DATA_BLOB containing an
  5171. //      ASN.1 encoded CERT_ENHKEY_USAGE (encoded via
  5172. //      CryptEncodeObject(X509_ENHANCED_KEY_USAGE).
  5173. //
  5174. //      CERT_NEXT_UPDATE_LOCATION_PROP_ID - location of the next update.
  5175. //      Currently only applicable to CTLs. pvData points to a CRYPT_DATA_BLOB
  5176. //      containing an ASN.1 encoded CERT_ALT_NAME_INFO (encoded via
  5177. //      CryptEncodeObject(X509_ALTERNATE_NAME)).
  5178. //
  5179. //      CERT_FRIENDLY_NAME_PROP_ID - friendly name for the cert, CRL or CTL.
  5180. //      pvData points to a CRYPT_DATA_BLOB. pbData is a pointer to a NULL
  5181. //      terminated unicode, wide character string.
  5182. //      cbData = (wcslen((LPWSTR) pbData) + 1) * sizeof(WCHAR).
  5183. //
  5184. //  For all the other PROP_IDs: an encoded PCRYPT_DATA_BLOB is passed in pvData.
  5185. //
  5186. //  If the property already exists, then, the old value is deleted and silently
  5187. //  replaced. Setting, pvData to NULL, deletes the property.
  5188. //--------------------------------------------------------------------------
  5189. WINCRYPT32API
  5190. BOOL
  5191. WINAPI
  5192. CertSetCertificateContextProperty(
  5193.     IN PCCERT_CONTEXT pCertContext,
  5194.     IN DWORD dwPropId,
  5195.     IN DWORD dwFlags,
  5196.     IN const void *pvData
  5197.     );
  5198.  
  5199. //+-------------------------------------------------------------------------
  5200. //  Get the property for the specified certificate context.
  5201. //
  5202. //  For CERT_KEY_PROV_HANDLE_PROP_ID, pvData points to a HCRYPTPROV.
  5203. //
  5204. //  For CERT_KEY_PROV_INFO_PROP_ID, pvData points to a CRYPT_KEY_PROV_INFO structure.
  5205. //  Elements pointed to by fields in the pvData structure follow the
  5206. //  structure. Therefore, *pcbData may exceed the size of the structure.
  5207. //
  5208. //  For CERT_KEY_CONTEXT_PROP_ID, pvData points to a CERT_KEY_CONTEXT structure.
  5209. //
  5210. //  For CERT_KEY_SPEC_PROP_ID, pvData points to a DWORD containing the KeySpec.
  5211. //  If the CERT_KEY_CONTEXT_PROP_ID exists, the KeySpec is obtained from there.
  5212. //  Otherwise, if the CERT_KEY_PROV_INFO_PROP_ID exists, its the source
  5213. //  of the KeySpec.
  5214. //
  5215. //  For CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID, if the hash
  5216. //  doesn't already exist, then, its computed via CryptHashCertificate()
  5217. //  and then set. pvData points to the computed hash. Normally, the length
  5218. //  is 20 bytes for SHA and 16 for MD5.
  5219. //
  5220. //  For all other PROP_IDs, pvData points to an encoded array of bytes.
  5221. //--------------------------------------------------------------------------
  5222. WINCRYPT32API
  5223. BOOL
  5224. WINAPI
  5225. CertGetCertificateContextProperty(
  5226.     IN PCCERT_CONTEXT pCertContext,
  5227.     IN DWORD dwPropId,
  5228.     OUT void *pvData,
  5229.     IN OUT DWORD *pcbData
  5230.     );
  5231.  
  5232. //+-------------------------------------------------------------------------
  5233. //  Enumerate the properties for the specified certificate context.
  5234. //
  5235. //  To get the first property, set dwPropId to 0. The ID of the first
  5236. //  property is returned. To get the next property, set dwPropId to the
  5237. //  ID returned by the last call. To enumerate all the properties continue
  5238. //  until 0 is returned.
  5239. //
  5240. //  CertGetCertificateContextProperty is called to get the property's data.
  5241. //
  5242. //  Note, since, the CERT_KEY_PROV_HANDLE_PROP_ID and CERT_KEY_SPEC_PROP_ID
  5243. //  properties are stored as fields in the CERT_KEY_CONTEXT_PROP_ID
  5244. //  property, they aren't enumerated individually.
  5245. //--------------------------------------------------------------------------
  5246. WINCRYPT32API
  5247. DWORD
  5248. WINAPI
  5249. CertEnumCertificateContextProperties(
  5250.     IN PCCERT_CONTEXT pCertContext,
  5251.     IN DWORD dwPropId
  5252.     );
  5253.  
  5254. //+-------------------------------------------------------------------------
  5255. //  Get the first or next CRL context from the store for the specified
  5256. //  issuer certificate. Perform the enabled verification checks on the CRL.
  5257. //
  5258. //  If the first or next CRL isn't found, NULL is returned.
  5259. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned. CRL_CONTEXT
  5260. //  must be freed by calling CertFreeCRLContext. However, the free must be
  5261. //  pPrevCrlContext on a subsequent call. CertDuplicateCRLContext
  5262. //  can be called to make a duplicate.
  5263. //
  5264. //  The pIssuerContext may have been obtained from this store, another store
  5265. //  or created by the caller application. When created by the caller, the
  5266. //  CertCreateCertificateContext function must have been called.
  5267. //
  5268. //  If pIssuerContext == NULL, finds all the CRLs in the store.
  5269. //
  5270. //  An issuer may have multiple CRLs. For example, it generates delta CRLs
  5271. //  using a X.509 v3 extension. pPrevCrlContext MUST BE NULL on the first
  5272. //  call to get the CRL. To get the next CRL for the issuer, the
  5273. //  pPrevCrlContext is set to the CRL_CONTEXT returned by a previous call.
  5274. //
  5275. //  NOTE: a NON-NULL pPrevCrlContext is always CertFreeCRLContext'ed by
  5276. //  this function, even for an error.
  5277. //
  5278. //  The following flags can be set in *pdwFlags to enable verification checks
  5279. //  on the returned CRL:
  5280. //      CERT_STORE_SIGNATURE_FLAG     - use the public key in the
  5281. //                                      issuer's certificate to verify the
  5282. //                                      signature on the returned CRL.
  5283. //                                      Note, if pIssuerContext->hCertStore ==
  5284. //                                      hCertStore, the store provider might
  5285. //                                      be able to eliminate a redo of
  5286. //                                      the signature verify.
  5287. //      CERT_STORE_TIME_VALIDITY_FLAG - get the current time and verify that
  5288. //                                      its within the CRL's ThisUpdate and
  5289. //                                      NextUpdate validity period.
  5290. //
  5291. //  If an enabled verification check fails, then, its flag is set upon return.
  5292. //
  5293. //  If pIssuerContext == NULL, then, an enabled CERT_STORE_SIGNATURE_FLAG
  5294. //  always fails and the CERT_STORE_NO_ISSUER_FLAG is also set.
  5295. //
  5296. //  For a verification check failure, a pointer to the first or next
  5297. //  CRL_CONTEXT is still returned and SetLastError isn't updated.
  5298. //--------------------------------------------------------------------------
  5299. WINCRYPT32API
  5300. PCCRL_CONTEXT
  5301. WINAPI
  5302. CertGetCRLFromStore(
  5303.     IN HCERTSTORE hCertStore,
  5304.     IN OPTIONAL PCCERT_CONTEXT pIssuerContext,
  5305.     IN PCCRL_CONTEXT pPrevCrlContext,
  5306.     IN OUT DWORD *pdwFlags
  5307.     );
  5308.  
  5309.  
  5310. //+-------------------------------------------------------------------------
  5311. //  Duplicate a CRL context
  5312. //--------------------------------------------------------------------------
  5313. WINCRYPT32API
  5314. PCCRL_CONTEXT
  5315. WINAPI
  5316. CertDuplicateCRLContext(
  5317.     IN PCCRL_CONTEXT pCrlContext
  5318.     );
  5319.  
  5320. //+-------------------------------------------------------------------------
  5321. //  Create a CRL context from the encoded CRL. The created
  5322. //  context isn't put in a store.
  5323. //
  5324. //  Makes a copy of the encoded CRL in the created context.
  5325. //
  5326. //  If unable to decode and create the CRL context, NULL is returned.
  5327. //  Otherwise, a pointer to a read only CRL_CONTEXT is returned.
  5328. //  CRL_CONTEXT must be freed by calling CertFreeCRLContext.
  5329. //  CertDuplicateCRLContext can be called to make a duplicate.
  5330. //
  5331. //  CertSetCRLContextProperty and CertGetCRLContextProperty can be called
  5332. //  to store properties for the CRL.
  5333. //--------------------------------------------------------------------------
  5334. WINCRYPT32API
  5335. PCCRL_CONTEXT
  5336. WINAPI
  5337. CertCreateCRLContext(
  5338.     IN DWORD dwCertEncodingType,
  5339.     IN const BYTE *pbCrlEncoded,
  5340.     IN DWORD cbCrlEncoded
  5341.     );
  5342.  
  5343. //+-------------------------------------------------------------------------
  5344. //  Free a CRL context
  5345. //
  5346. //  There needs to be a corresponding free for each context obtained by a
  5347. //  get, duplicate or create.
  5348. //--------------------------------------------------------------------------
  5349. WINCRYPT32API
  5350. BOOL
  5351. WINAPI
  5352. CertFreeCRLContext(
  5353.     IN PCCRL_CONTEXT pCrlContext
  5354.     );
  5355.  
  5356. //+-------------------------------------------------------------------------
  5357. //  Set the property for the specified CRL context.
  5358. //
  5359. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  5360. //--------------------------------------------------------------------------
  5361. WINCRYPT32API
  5362. BOOL
  5363. WINAPI
  5364. CertSetCRLContextProperty(
  5365.     IN PCCRL_CONTEXT pCrlContext,
  5366.     IN DWORD dwPropId,
  5367.     IN DWORD dwFlags,
  5368.     IN const void *pvData
  5369.     );
  5370.  
  5371. //+-------------------------------------------------------------------------
  5372. //  Get the property for the specified CRL context.
  5373. //
  5374. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  5375. //
  5376. //  CERT_SHA1_HASH_PROP_ID or CERT_MD5_HASH_PROP_ID is the predefined
  5377. //  property of most interest.
  5378. //--------------------------------------------------------------------------
  5379. WINCRYPT32API
  5380. BOOL
  5381. WINAPI
  5382. CertGetCRLContextProperty(
  5383.     IN PCCRL_CONTEXT pCrlContext,
  5384.     IN DWORD dwPropId,
  5385.     OUT void *pvData,
  5386.     IN OUT DWORD *pcbData
  5387.     );
  5388.  
  5389. //+-------------------------------------------------------------------------
  5390. //  Enumerate the properties for the specified CRL context.
  5391. //
  5392. //  To get the first property, set dwPropId to 0. The ID of the first
  5393. //  property is returned. To get the next property, set dwPropId to the
  5394. //  ID returned by the last call. To enumerate all the properties continue
  5395. //  until 0 is returned.
  5396. //
  5397. //  CertGetCRLContextProperty is called to get the property's data.
  5398. //--------------------------------------------------------------------------
  5399. WINCRYPT32API
  5400. DWORD
  5401. WINAPI
  5402. CertEnumCRLContextProperties(
  5403.     IN PCCRL_CONTEXT pCrlContext,
  5404.     IN DWORD dwPropId
  5405.     );
  5406.  
  5407. //+-------------------------------------------------------------------------
  5408. // Add certificate/CRL, encoded, context or element disposition values.
  5409. //--------------------------------------------------------------------------
  5410. #define CERT_STORE_ADD_NEW                  1
  5411. #define CERT_STORE_ADD_USE_EXISTING         2
  5412. #define CERT_STORE_ADD_REPLACE_EXISTING     3
  5413. #define CERT_STORE_ADD_ALWAYS               4
  5414.  
  5415. //+-------------------------------------------------------------------------
  5416. //  Add the encoded certificate to the store according to the specified
  5417. //  disposition action.
  5418. //
  5419. //  Makes a copy of the encoded certificate before adding to the store.
  5420. //
  5421. //  dwAddDispostion specifies the action to take if the certificate
  5422. //  already exists in the store. This parameter must be one of the following
  5423. //  values:
  5424. //    CERT_STORE_ADD_NEW
  5425. //      Fails if the certificate already exists in the store. LastError
  5426. //      is set to CRYPT_E_EXISTS.
  5427. //    CERT_STORE_ADD_USE_EXISTING
  5428. //      If the certifcate already exists, then, its used and if ppCertContext
  5429. //      is non-NULL, the existing context is duplicated.
  5430. //    CERT_STORE_ADD_REPLACE_EXISTING
  5431. //      If the certificate already exists, then, the existing certificate
  5432. //      context is deleted before creating and adding the new context.
  5433. //    CERT_STORE_ADD_ALWAYS
  5434. //      No check is made to see if the certificate already exists. A
  5435. //      new certificate context is always created. This may lead to
  5436. //      duplicates in the store.
  5437. //
  5438. //  CertGetSubjectCertificateFromStore is called to determine if the
  5439. //  certificate already exists in the store.
  5440. //
  5441. //  ppCertContext can be NULL, indicating the caller isn't interested
  5442. //  in getting the CERT_CONTEXT of the added or existing certificate.
  5443. //--------------------------------------------------------------------------
  5444. WINCRYPT32API
  5445. BOOL
  5446. WINAPI
  5447. CertAddEncodedCertificateToStore(
  5448.     IN HCERTSTORE hCertStore,
  5449.     IN DWORD dwCertEncodingType,
  5450.     IN const BYTE *pbCertEncoded,
  5451.     IN DWORD cbCertEncoded,
  5452.     IN DWORD dwAddDisposition,
  5453.     OUT OPTIONAL PCCERT_CONTEXT *ppCertContext
  5454.     );
  5455.  
  5456. //+-------------------------------------------------------------------------
  5457. //  Add the certificate context to the store according to the specified
  5458. //  disposition action.
  5459. //
  5460. //  In addition to the encoded certificate, the context's properties are
  5461. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5462. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5463. //
  5464. //  Makes a copy of the certificate context before adding to the store.
  5465. //
  5466. //  dwAddDispostion specifies the action to take if the certificate
  5467. //  already exists in the store. This parameter must be one of the following
  5468. //  values:
  5469. //    CERT_STORE_ADD_NEW
  5470. //      Fails if the certificate already exists in the store. LastError
  5471. //      is set to CRYPT_E_EXISTS.
  5472. //    CERT_STORE_ADD_USE_EXISTING
  5473. //      If the certifcate already exists, then, its used and if ppStoreContext
  5474. //      is non-NULL, the existing context is duplicated. Iterates
  5475. //      through pCertContext's properties and only copies the properties
  5476. //      that don't already exist. The SHA1 and MD5 hash properties aren't
  5477. //      copied.
  5478. //    CERT_STORE_ADD_REPLACE_EXISTING
  5479. //      If the certificate already exists, then, the existing certificate
  5480. //      context is deleted before creating and adding a new context.
  5481. //      Properties are copied before doing the add.
  5482. //    CERT_STORE_ADD_ALWAYS
  5483. //      No check is made to see if the certificate already exists. A
  5484. //      new certificate context is always created and added. This may lead to
  5485. //      duplicates in the store. Properties are
  5486. //      copied before doing the add.
  5487. //
  5488. //  CertGetSubjectCertificateFromStore is called to determine if the
  5489. //  certificate already exists in the store.
  5490. //
  5491. //  ppStoreContext can be NULL, indicating the caller isn't interested
  5492. //  in getting the CERT_CONTEXT of the added or existing certificate.
  5493. //--------------------------------------------------------------------------
  5494. WINCRYPT32API
  5495. BOOL
  5496. WINAPI
  5497. CertAddCertificateContextToStore(
  5498.     IN HCERTSTORE hCertStore,
  5499.     IN PCCERT_CONTEXT pCertContext,
  5500.     IN DWORD dwAddDisposition,
  5501.     OUT OPTIONAL PCCERT_CONTEXT *ppStoreContext
  5502.     );
  5503.  
  5504.  
  5505. //+-------------------------------------------------------------------------
  5506. //  Certificate Store Context Types
  5507. //--------------------------------------------------------------------------
  5508. #define CERT_STORE_CERTIFICATE_CONTEXT  1
  5509. #define CERT_STORE_CRL_CONTEXT          2
  5510. #define CERT_STORE_CTL_CONTEXT          3
  5511.  
  5512. //+-------------------------------------------------------------------------
  5513. //  Certificate Store Context Bit Flags
  5514. //--------------------------------------------------------------------------
  5515. #define CERT_STORE_ALL_CONTEXT_FLAG             (~0UL)
  5516. #define CERT_STORE_CERTIFICATE_CONTEXT_FLAG     \
  5517.                 (1 << CERT_STORE_CERTIFICATE_CONTEXT)
  5518. #define CERT_STORE_CRL_CONTEXT_FLAG             \
  5519.                 (1 << CERT_STORE_CRL_CONTEXT)
  5520. #define CERT_STORE_CTL_CONTEXT_FLAG             \
  5521.                 (1 << CERT_STORE_CTL_CONTEXT)
  5522.  
  5523. //+-------------------------------------------------------------------------
  5524. //  Add the serialized certificate or CRL element to the store.
  5525. //
  5526. //  The serialized element contains the encoded certificate, CRL or CTL and
  5527. //  its properties, such as, CERT_KEY_PROV_INFO_PROP_ID.
  5528. //
  5529. //  If hCertStore is NULL, creates a certificate, CRL or CTL context not
  5530. //  residing in any store.
  5531. //
  5532. //  dwAddDispostion specifies the action to take if the certificate or CRL
  5533. //  already exists in the store. See CertAddCertificateContextToStore for a
  5534. //  list of and actions taken.
  5535. //
  5536. //  dwFlags currently isn't used and should be set to 0.
  5537. //
  5538. //  dwContextTypeFlags specifies the set of allowable contexts. For example, to
  5539. //  add either a certificate or CRL, set dwContextTypeFlags to:
  5540. //      CERT_STORE_CERTIFICATE_CONTEXT_FLAG | CERT_STORE_CRL_CONTEXT_FLAG
  5541. //
  5542. //  *pdwContextType is updated with the type of the context returned in
  5543. //  *ppvContxt. pdwContextType or ppvContext can be NULL, indicating the
  5544. //  caller isn't interested in getting the output. If *ppvContext is
  5545. //  returned it must be freed by calling CertFreeCertificateContext or
  5546. //  CertFreeCRLContext.
  5547. //--------------------------------------------------------------------------
  5548. WINCRYPT32API
  5549. BOOL
  5550. WINAPI
  5551. CertAddSerializedElementToStore(
  5552.     IN HCERTSTORE hCertStore,
  5553.     IN const BYTE *pbElement,
  5554.     IN DWORD cbElement,
  5555.     IN DWORD dwAddDisposition,
  5556.     IN DWORD dwFlags,
  5557.     IN DWORD dwContextTypeFlags,
  5558.     OUT OPTIONAL DWORD *pdwContextType,
  5559.     OUT OPTIONAL const void **ppvContext
  5560.     );
  5561.  
  5562. //+-------------------------------------------------------------------------
  5563. //  Delete the specified certificate from the store.
  5564. //
  5565. //  All subsequent gets or finds for the certificate will fail. However,
  5566. //  memory allocated for the certificate isn't freed until all of its contexts
  5567. //  have also been freed.
  5568. //
  5569. //  The pCertContext is obtained from a get, enum, find or duplicate.
  5570. //
  5571. //  Some store provider implementations might also delete the issuer's CRLs
  5572. //  if this is the last certificate for the issuer in the store.
  5573. //
  5574. //  NOTE: the pCertContext is always CertFreeCertificateContext'ed by
  5575. //  this function, even for an error.
  5576. //--------------------------------------------------------------------------
  5577. WINCRYPT32API
  5578. BOOL
  5579. WINAPI
  5580. CertDeleteCertificateFromStore(
  5581.     IN PCCERT_CONTEXT pCertContext
  5582.     );
  5583.  
  5584. //+-------------------------------------------------------------------------
  5585. //  Add the encoded CRL to the store according to the specified
  5586. //  disposition option.
  5587. //
  5588. //  Makes a copy of the encoded CRL before adding to the store.
  5589. //
  5590. //  dwAddDispostion specifies the action to take if the CRL
  5591. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  5592. //  list of and actions taken.
  5593. //
  5594. //  Compares the CRL's Issuer to determine if the CRL already exists in the
  5595. //  store.
  5596. //
  5597. //  ppCrlContext can be NULL, indicating the caller isn't interested
  5598. //  in getting the CRL_CONTEXT of the added or existing CRL.
  5599. //--------------------------------------------------------------------------
  5600. WINCRYPT32API
  5601. BOOL
  5602. WINAPI
  5603. CertAddEncodedCRLToStore(
  5604.     IN HCERTSTORE hCertStore,
  5605.     IN DWORD dwCertEncodingType,
  5606.     IN const BYTE *pbCrlEncoded,
  5607.     IN DWORD cbCrlEncoded,
  5608.     IN DWORD dwAddDisposition,
  5609.     OUT OPTIONAL PCCRL_CONTEXT *ppCrlContext
  5610.     );
  5611.  
  5612. //+-------------------------------------------------------------------------
  5613. //  Add the CRL context to the store according to the specified
  5614. //  disposition option.
  5615. //
  5616. //  In addition to the encoded CRL, the context's properties are
  5617. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5618. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5619. //
  5620. //  Makes a copy of the encoded CRL before adding to the store.
  5621. //
  5622. //  dwAddDispostion specifies the action to take if the CRL
  5623. //  already exists in the store. See CertAddCertificateContextToStore for a
  5624. //  list of and actions taken.
  5625. //
  5626. //  Compares the CRL's Issuer, ThisUpdate and NextUpdate to determine
  5627. //  if the CRL already exists in the store.
  5628. //
  5629. //  ppStoreContext can be NULL, indicating the caller isn't interested
  5630. //  in getting the CRL_CONTEXT of the added or existing CRL.
  5631. //--------------------------------------------------------------------------
  5632. WINCRYPT32API
  5633. BOOL
  5634. WINAPI
  5635. CertAddCRLContextToStore(
  5636.     IN HCERTSTORE hCertStore,
  5637.     IN PCCRL_CONTEXT pCrlContext,
  5638.     IN DWORD dwAddDisposition,
  5639.     OUT OPTIONAL PCCRL_CONTEXT *ppStoreContext
  5640.     );
  5641.  
  5642. //+-------------------------------------------------------------------------
  5643. //  Delete the specified CRL from the store.
  5644. //
  5645. //  All subsequent gets for the CRL will fail. However,
  5646. //  memory allocated for the CRL isn't freed until all of its contexts
  5647. //  have also been freed.
  5648. //
  5649. //  The pCrlContext is obtained from a get or duplicate.
  5650. //
  5651. //  NOTE: the pCrlContext is always CertFreeCRLContext'ed by
  5652. //  this function, even for an error.
  5653. //--------------------------------------------------------------------------
  5654. WINCRYPT32API
  5655. BOOL
  5656. WINAPI
  5657. CertDeleteCRLFromStore(
  5658.     IN PCCRL_CONTEXT pCrlContext
  5659.     );
  5660.  
  5661. //+-------------------------------------------------------------------------
  5662. //  Serialize the certificate context's encoded certificate and its
  5663. //  properties.
  5664. //--------------------------------------------------------------------------
  5665. WINCRYPT32API
  5666. BOOL
  5667. WINAPI
  5668. CertSerializeCertificateStoreElement(
  5669.     IN PCCERT_CONTEXT pCertContext,
  5670.     IN DWORD dwFlags,
  5671.     OUT BYTE *pbElement,
  5672.     IN OUT DWORD *pcbElement
  5673.     );
  5674.  
  5675.  
  5676. //+-------------------------------------------------------------------------
  5677. //  Serialize the CRL context's encoded CRL and its properties.
  5678. //--------------------------------------------------------------------------
  5679. WINCRYPT32API
  5680. BOOL
  5681. WINAPI
  5682. CertSerializeCRLStoreElement(
  5683.     IN PCCRL_CONTEXT pCrlContext,
  5684.     IN DWORD dwFlags,
  5685.     OUT BYTE *pbElement,
  5686.     IN OUT DWORD *pcbElement
  5687.     );
  5688.  
  5689.  
  5690. //+=========================================================================
  5691. //  Certificate Trust List (CTL) Store Data Structures and APIs
  5692. //==========================================================================
  5693.  
  5694. //+-------------------------------------------------------------------------
  5695. //  Duplicate a CTL context
  5696. //--------------------------------------------------------------------------
  5697. WINCRYPT32API
  5698. PCCTL_CONTEXT
  5699. WINAPI
  5700. CertDuplicateCTLContext(
  5701.     IN PCCTL_CONTEXT pCtlContext
  5702.     );
  5703.  
  5704. //+-------------------------------------------------------------------------
  5705. //  Create a CTL context from the encoded CTL. The created
  5706. //  context isn't put in a store.
  5707. //
  5708. //  Makes a copy of the encoded CTL in the created context.
  5709. //
  5710. //  If unable to decode and create the CTL context, NULL is returned.
  5711. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned.
  5712. //  CTL_CONTEXT must be freed by calling CertFreeCTLContext.
  5713. //  CertDuplicateCTLContext can be called to make a duplicate.
  5714. //
  5715. //  CertSetCTLContextProperty and CertGetCTLContextProperty can be called
  5716. //  to store properties for the CTL.
  5717. //--------------------------------------------------------------------------
  5718. WINCRYPT32API
  5719. PCCTL_CONTEXT
  5720. WINAPI
  5721. CertCreateCTLContext(
  5722.     IN DWORD dwMsgAndCertEncodingType,
  5723.     IN const BYTE *pbCtlEncoded,
  5724.     IN DWORD cbCtlEncoded
  5725.     );
  5726.  
  5727. //+-------------------------------------------------------------------------
  5728. //  Free a CTL context
  5729. //
  5730. //  There needs to be a corresponding free for each context obtained by a
  5731. //  get, duplicate or create.
  5732. //--------------------------------------------------------------------------
  5733. WINCRYPT32API
  5734. BOOL
  5735. WINAPI
  5736. CertFreeCTLContext(
  5737.     IN PCCTL_CONTEXT pCtlContext
  5738.     );
  5739.  
  5740. //+-------------------------------------------------------------------------
  5741. //  Set the property for the specified CTL context.
  5742. //
  5743. //  Same Property Ids and semantics as CertSetCertificateContextProperty.
  5744. //--------------------------------------------------------------------------
  5745. WINCRYPT32API
  5746. BOOL
  5747. WINAPI
  5748. CertSetCTLContextProperty(
  5749.     IN PCCTL_CONTEXT pCtlContext,
  5750.     IN DWORD dwPropId,
  5751.     IN DWORD dwFlags,
  5752.     IN const void *pvData
  5753.     );
  5754.  
  5755. //+-------------------------------------------------------------------------
  5756. //  Get the property for the specified CTL context.
  5757. //
  5758. //  Same Property Ids and semantics as CertGetCertificateContextProperty.
  5759. //
  5760. //  CERT_SHA1_HASH_PROP_ID or CERT_NEXT_UPDATE_LOCATION_PROP_ID are the
  5761. //  predefined properties of most interest.
  5762. //--------------------------------------------------------------------------
  5763. WINCRYPT32API
  5764. BOOL
  5765. WINAPI
  5766. CertGetCTLContextProperty(
  5767.     IN PCCTL_CONTEXT pCtlContext,
  5768.     IN DWORD dwPropId,
  5769.     OUT void *pvData,
  5770.     IN OUT DWORD *pcbData
  5771.     );
  5772.  
  5773. //+-------------------------------------------------------------------------
  5774. //  Enumerate the properties for the specified CTL context.
  5775. //--------------------------------------------------------------------------
  5776. WINCRYPT32API
  5777. DWORD
  5778. WINAPI
  5779. CertEnumCTLContextProperties(
  5780.     IN PCCTL_CONTEXT pCtlContext,
  5781.     IN DWORD dwPropId
  5782.     );
  5783.  
  5784. //+-------------------------------------------------------------------------
  5785. //  Enumerate the CTL contexts in the store.
  5786. //
  5787. //  If a CTL isn't found, NULL is returned.
  5788. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5789. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  5790. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5791. //  can be called to make a duplicate.
  5792. //
  5793. //  pPrevCtlContext MUST BE NULL to enumerate the first
  5794. //  CTL in the store. Successive CTLs are enumerated by setting
  5795. //  pPrevCtlContext to the CTL_CONTEXT returned by a previous call.
  5796. //
  5797. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5798. //  this function, even for an error.
  5799. //--------------------------------------------------------------------------
  5800. WINCRYPT32API
  5801. PCCTL_CONTEXT
  5802. WINAPI
  5803. CertEnumCTLsInStore(
  5804.     IN HCERTSTORE hCertStore,
  5805.     IN PCCTL_CONTEXT pPrevCtlContext
  5806.     );
  5807.  
  5808. //+-------------------------------------------------------------------------
  5809. //  Attempt to find the specified subject in the CTL.
  5810. //
  5811. //  For CTL_CERT_SUBJECT_TYPE, pvSubject points to a CERT_CONTEXT. The CTL's
  5812. //  SubjectAlgorithm is examined to determine the representation of the
  5813. //  subject's identity. Initially, only SHA1 or MD5 hash will be supported.
  5814. //  The appropriate hash property is obtained from the CERT_CONTEXT.
  5815. //
  5816. //  For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO
  5817. //  structure which contains the SubjectAlgorithm to be matched in the CTL
  5818. //  and the SubjectIdentifer to be matched in one of the CTL entries.
  5819. //
  5820. //  The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier
  5821. //  is used as the key in searching the subject entries. A binary
  5822. //  memory comparison is done between the key and the entry's SubjectIdentifer.
  5823. //
  5824. //  dwEncodingType isn't used for either of the above SubjectTypes.
  5825. //--------------------------------------------------------------------------
  5826. WINCRYPT32API
  5827. PCTL_ENTRY
  5828. WINAPI
  5829. CertFindSubjectInCTL(
  5830.     IN DWORD dwEncodingType,
  5831.     IN DWORD dwSubjectType,
  5832.     IN void *pvSubject,
  5833.     IN PCCTL_CONTEXT pCtlContext,
  5834.     IN DWORD dwFlags
  5835.     );
  5836.  
  5837. // Subject Types:
  5838. //  CTL_ANY_SUBJECT_TYPE, pvSubject points to following CTL_ANY_SUBJECT_INFO.
  5839. //  CTL_CERT_SUBJECT_TYPE, pvSubject points to CERT_CONTEXT.
  5840. #define CTL_ANY_SUBJECT_TYPE            1
  5841. #define CTL_CERT_SUBJECT_TYPE           2
  5842.  
  5843. typedef struct _CTL_ANY_SUBJECT_INFO {
  5844.     CRYPT_ALGORITHM_IDENTIFIER  SubjectAlgorithm;
  5845.     CRYPT_DATA_BLOB             SubjectIdentifier;
  5846. } CTL_ANY_SUBJECT_INFO, *PCTL_ANY_SUBJECT_INFO;
  5847.  
  5848. //+-------------------------------------------------------------------------
  5849. //  Find the first or next CTL context in the store.
  5850. //
  5851. //  The CTL is found according to the dwFindType and its pvFindPara.
  5852. //  See below for a list of the find types and its parameters.
  5853. //
  5854. //  Currently dwFindFlags isn't used and must be set to 0.
  5855. //
  5856. //  Usage of dwMsgAndCertEncodingType depends on the dwFindType.
  5857. //
  5858. //  If the first or next CTL isn't found, NULL is returned.
  5859. //  Otherwise, a pointer to a read only CTL_CONTEXT is returned. CTL_CONTEXT
  5860. //  must be freed by calling CertFreeCTLContext or is freed when passed as the
  5861. //  pPrevCtlContext on a subsequent call. CertDuplicateCTLContext
  5862. //  can be called to make a duplicate.
  5863. //
  5864. //  pPrevCtlContext MUST BE NULL on the first
  5865. //  call to find the CTL. To find the next CTL, the
  5866. //  pPrevCtlContext is set to the CTL_CONTEXT returned by a previous call.
  5867. //
  5868. //  NOTE: a NON-NULL pPrevCtlContext is always CertFreeCTLContext'ed by
  5869. //  this function, even for an error.
  5870. //--------------------------------------------------------------------------
  5871. WINCRYPT32API
  5872. PCCTL_CONTEXT
  5873. WINAPI
  5874. CertFindCTLInStore(
  5875.     IN HCERTSTORE hCertStore,
  5876.     IN DWORD dwMsgAndCertEncodingType,
  5877.     IN DWORD dwFindFlags,
  5878.     IN DWORD dwFindType,
  5879.     IN const void *pvFindPara,
  5880.     IN PCCTL_CONTEXT pPrevCtlContext
  5881.     );
  5882.  
  5883. #define CTL_FIND_ANY                0
  5884. #define CTL_FIND_SHA1_HASH          1
  5885. #define CTL_FIND_MD5_HASH           2
  5886. #define CTL_FIND_USAGE              3
  5887. #define CTL_FIND_SUBJECT            4
  5888.  
  5889. typedef struct _CTL_FIND_USAGE_PARA {
  5890.     DWORD               cbSize;
  5891.     CTL_USAGE           SubjectUsage;   // optional
  5892.     CRYPT_DATA_BLOB     ListIdentifier; // optional
  5893.     PCERT_INFO          pSigner;        // optional
  5894. } CTL_FIND_USAGE_PARA, *PCTL_FIND_USAGE_PARA;
  5895.  
  5896. #define CTL_FIND_NO_LIST_ID_CBDATA  0xFFFFFFFF
  5897. #define CTL_FIND_NO_SIGNER_PTR      ((PCERT_INFO) 0xFFFFFFFF)
  5898.  
  5899. #define CTL_FIND_SAME_USAGE_FLAG    0x1
  5900.  
  5901.  
  5902. typedef struct _CTL_FIND_SUBJECT_PARA {
  5903.     DWORD                   cbSize;
  5904.     PCTL_FIND_USAGE_PARA    pUsagePara; // optional
  5905.     DWORD                   dwSubjectType;
  5906.     void                    *pvSubject;
  5907. } CTL_FIND_SUBJECT_PARA, *PCTL_FIND_SUBJECT_PARA;
  5908.  
  5909.  
  5910. //+-------------------------------------------------------------------------
  5911. //  CTL_FIND_ANY
  5912. //
  5913. //  Find any CTL.
  5914. //
  5915. //  pvFindPara isn't used.
  5916. //--------------------------------------------------------------------------
  5917.  
  5918. //+-------------------------------------------------------------------------
  5919. //  CTL_FIND_SHA1_HASH
  5920. //  CTL_FIND_MD5_HASH
  5921. //
  5922. //  Find a CTL with the specified hash.
  5923. //
  5924. //  pvFindPara points to a CRYPT_HASH_BLOB.
  5925. //--------------------------------------------------------------------------
  5926.  
  5927. //+-------------------------------------------------------------------------
  5928. //  CTL_FIND_USAGE
  5929. //
  5930. //  Find a CTL having the specified usage identifiers, list identifier or
  5931. //  signer. The CertEncodingType of the signer is obtained from the
  5932. //  dwMsgAndCertEncodingType parameter.
  5933. //
  5934. //  pvFindPara points to a CTL_FIND_USAGE_PARA data structure. The
  5935. //  SubjectUsage.cUsageIdentifer can be 0 to match any usage. The
  5936. //  ListIdentifier.cbData can be 0 to match any list identifier. To only match
  5937. //  CTLs without a ListIdentifier, cbData must be set to
  5938. //  CTL_FIND_NO_LIST_ID_CBDATA. pSigner can be NULL to match any signer. Only
  5939. //  the Issuer and SerialNumber fields of the pSigner's PCERT_INFO are used.
  5940. //  To only match CTLs without a signer, pSigner must be set to
  5941. //  CTL_FIND_NO_SIGNER_PTR.
  5942. //
  5943. //  The CTL_FIND_SAME_USAGE_FLAG can be set in dwFindFlags to
  5944. //  only match CTLs with the same usage identifiers. CTLs having additional
  5945. //  usage identifiers aren't matched. For example, if only "1.2.3" is specified
  5946. //  in CTL_FIND_USAGE_PARA, then, for a match, the CTL must only contain
  5947. //  "1.2.3" and not any additional usage identifers.
  5948. //--------------------------------------------------------------------------
  5949.  
  5950. //+-------------------------------------------------------------------------
  5951. //  CTL_FIND_SUBJECT
  5952. //
  5953. //  Find a CTL having the specified subject. CertFindSubjectInCTL can be
  5954. //  called to get a pointer to the subject's entry in the CTL.  pUsagePara can
  5955. //  optionally be set to enable the above CTL_FIND_USAGE matching.
  5956. //
  5957. //  pvFindPara points to a CTL_FIND_SUBJECT_PARA data structure.
  5958. //--------------------------------------------------------------------------
  5959.  
  5960. //+-------------------------------------------------------------------------
  5961. //  Add the encoded CTL to the store according to the specified
  5962. //  disposition option.
  5963. //
  5964. //  Makes a copy of the encoded CTL before adding to the store.
  5965. //
  5966. //  dwAddDispostion specifies the action to take if the CTL
  5967. //  already exists in the store. See CertAddEncodedCertificateToStore for a
  5968. //  list of and actions taken.
  5969. //
  5970. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  5971. //  to determine if the CTL already exists in the store.
  5972. //
  5973. //  ppCtlContext can be NULL, indicating the caller isn't interested
  5974. //  in getting the CTL_CONTEXT of the added or existing CTL.
  5975. //--------------------------------------------------------------------------
  5976. WINCRYPT32API
  5977. BOOL
  5978. WINAPI
  5979. CertAddEncodedCTLToStore(
  5980.     IN HCERTSTORE hCertStore,
  5981.     IN DWORD dwMsgAndCertEncodingType,
  5982.     IN const BYTE *pbCtlEncoded,
  5983.     IN DWORD cbCtlEncoded,
  5984.     IN DWORD dwAddDisposition,
  5985.     OUT OPTIONAL PCCTL_CONTEXT *ppCtlContext
  5986.     );
  5987.  
  5988. //+-------------------------------------------------------------------------
  5989. //  Add the CTL context to the store according to the specified
  5990. //  disposition option.
  5991. //
  5992. //  In addition to the encoded CTL, the context's properties are
  5993. //  also copied.  Note, the CERT_KEY_CONTEXT_PROP_ID property (and its
  5994. //  CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_SPEC_PROP_ID) isn't copied.
  5995. //
  5996. //  Makes a copy of the encoded CTL before adding to the store.
  5997. //
  5998. //  dwAddDispostion specifies the action to take if the CTL
  5999. //  already exists in the store. See CertAddCertificateContextToStore for a
  6000. //  list of and actions taken.
  6001. //
  6002. //  Compares the CTL's SubjectUsage, ListIdentifier and any of its signers
  6003. //  to determine if the CTL already exists in the store.
  6004. //
  6005. //  ppStoreContext can be NULL, indicating the caller isn't interested
  6006. //  in getting the CTL_CONTEXT of the added or existing CTL.
  6007. //--------------------------------------------------------------------------
  6008. WINCRYPT32API
  6009. BOOL
  6010. WINAPI
  6011. CertAddCTLContextToStore(
  6012.     IN HCERTSTORE hCertStore,
  6013.     IN PCCTL_CONTEXT pCtlContext,
  6014.     IN DWORD dwAddDisposition,
  6015.     OUT OPTIONAL PCCTL_CONTEXT *ppStoreContext
  6016.     );
  6017.  
  6018. //+-------------------------------------------------------------------------
  6019. //  Serialize the CTL context's encoded CTL and its properties.
  6020. //--------------------------------------------------------------------------
  6021. WINCRYPT32API
  6022. BOOL
  6023. WINAPI
  6024. CertSerializeCTLStoreElement(
  6025.     IN PCCTL_CONTEXT pCtlContext,
  6026.     IN DWORD dwFlags,
  6027.     OUT BYTE *pbElement,
  6028.     IN OUT DWORD *pcbElement
  6029.     );
  6030.  
  6031. //+-------------------------------------------------------------------------
  6032. //  Delete the specified CTL from the store.
  6033. //
  6034. //  All subsequent gets for the CTL will fail. However,
  6035. //  memory allocated for the CTL isn't freed until all of its contexts
  6036. //  have also been freed.
  6037. //
  6038. //  The pCtlContext is obtained from a get or duplicate.
  6039. //
  6040. //  NOTE: the pCtlContext is always CertFreeCTLContext'ed by
  6041. //  this function, even for an error.
  6042. //--------------------------------------------------------------------------
  6043. WINCRYPT32API
  6044. BOOL
  6045. WINAPI
  6046. CertDeleteCTLFromStore(
  6047.     IN PCCTL_CONTEXT pCtlContext
  6048.     );
  6049.  
  6050.  
  6051. //+=========================================================================
  6052. //  Enhanced Key Usage Helper Functions
  6053. //==========================================================================
  6054.  
  6055. //+-------------------------------------------------------------------------
  6056. //  Get the enhanced key usage extension or property from the certificate
  6057. //  and decode.
  6058. //
  6059. //  If the CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  6060. //  extension.
  6061. //
  6062. //  If the CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG is set, then, only get the
  6063. //  property.
  6064. //--------------------------------------------------------------------------
  6065. WINCRYPT32API
  6066. BOOL
  6067. WINAPI
  6068. CertGetEnhancedKeyUsage(
  6069.     IN PCCERT_CONTEXT pCertContext,
  6070.     IN DWORD dwFlags,
  6071.     OUT PCERT_ENHKEY_USAGE pUsage,
  6072.     IN OUT DWORD *pcbUsage
  6073.     );
  6074.  
  6075. //+-------------------------------------------------------------------------
  6076. //  Set the enhanced key usage property for the certificate.
  6077. //--------------------------------------------------------------------------
  6078. WINCRYPT32API
  6079. BOOL
  6080. WINAPI
  6081. CertSetEnhancedKeyUsage(
  6082.     IN PCCERT_CONTEXT pCertContext,
  6083.     IN PCERT_ENHKEY_USAGE pUsage
  6084.     );
  6085.  
  6086. //+-------------------------------------------------------------------------
  6087. //  Add the usage identifier to the certificate's enhanced key usage property.
  6088. //--------------------------------------------------------------------------
  6089. WINCRYPT32API
  6090. BOOL
  6091. WINAPI
  6092. CertAddEnhancedKeyUsageIdentifier(
  6093.     IN PCCERT_CONTEXT pCertContext,
  6094.     IN LPCSTR pszUsageIdentifier
  6095.     );
  6096.  
  6097.  
  6098. //+-------------------------------------------------------------------------
  6099. //  Remove the usage identifier from the certificate's enhanced key usage
  6100. //  property.
  6101. //--------------------------------------------------------------------------
  6102. WINCRYPT32API
  6103. BOOL
  6104. WINAPI
  6105. CertRemoveEnhancedKeyUsageIdentifier(
  6106.     IN PCCERT_CONTEXT pCertContext,
  6107.     IN LPCSTR pszUsageIdentifier
  6108.     );
  6109.  
  6110.  
  6111. //+=========================================================================
  6112. //  Cryptographic Message helper functions for verifying and signing a
  6113. //  CTL.
  6114. //==========================================================================
  6115.  
  6116. //+-------------------------------------------------------------------------
  6117. //  Get and verify the signer of a cryptographic message.
  6118. //
  6119. //  To verify a CTL, the hCryptMsg is obtained from the CTL_CONTEXT's
  6120. //  hCryptMsg field.
  6121. //
  6122. //  If CMSG_TRUSTED_SIGNER_FLAG is set, then, treat the Signer stores as being
  6123. //  trusted and only search them to find the certificate corresponding to the
  6124. //  signer's issuer and serial number.  Otherwise, the SignerStores are
  6125. //  optionally provided to supplement the message's store of certificates.
  6126. //  If a signer certificate is found, its public key is used to verify
  6127. //  the message signature. The CMSG_SIGNER_ONLY_FLAG can be set to
  6128. //  return the signer without doing the signature verify.
  6129. //
  6130. //  If CMSG_USE_SIGNER_INDEX_FLAG is set, then, only get the signer specified
  6131. //  by *pdwSignerIndex. Otherwise, iterate through all the signers
  6132. //  until a signer verifies or no more signers.
  6133. //
  6134. //  For a verified signature, *ppSigner is updated with certificate context
  6135. //  of the signer and *pdwSignerIndex is updated with the index of the signer.
  6136. //  ppSigner and/or pdwSignerIndex can be NULL, indicating the caller isn't
  6137. //  interested in getting the CertContext and/or index of the signer.
  6138. //--------------------------------------------------------------------------
  6139. WINCRYPT32API
  6140. BOOL
  6141. WINAPI
  6142. CryptMsgGetAndVerifySigner(
  6143.     IN HCRYPTMSG hCryptMsg,
  6144.     IN DWORD cSignerStore,
  6145.     IN OPTIONAL HCERTSTORE *rghSignerStore,
  6146.     IN DWORD dwFlags,
  6147.     OUT OPTIONAL PCCERT_CONTEXT *ppSigner,
  6148.     IN OUT OPTIONAL DWORD *pdwSignerIndex
  6149.     );
  6150.  
  6151. #define CMSG_TRUSTED_SIGNER_FLAG            0x1
  6152. #define CMSG_SIGNER_ONLY_FLAG               0x2
  6153. #define CMSG_USE_SIGNER_INDEX_FLAG          0x4
  6154.  
  6155. //+-------------------------------------------------------------------------
  6156. //  Sign an encoded CTL.
  6157. //
  6158. //  The pbCtlContent can be obtained via a CTL_CONTEXT's pbCtlContent
  6159. //  field or via a CryptEncodeObject(PKCS_CTL).
  6160. //--------------------------------------------------------------------------
  6161. WINCRYPT32API
  6162. BOOL
  6163. WINAPI
  6164. CryptMsgSignCTL(
  6165.     IN DWORD dwMsgEncodingType,
  6166.     IN BYTE *pbCtlContent,
  6167.     IN DWORD cbCtlContent,
  6168.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  6169.     IN DWORD dwFlags,
  6170.     OUT BYTE *pbEncoded,
  6171.     IN OUT DWORD *pcbEncoded
  6172.     );
  6173.  
  6174. //+-------------------------------------------------------------------------
  6175. //  Encode the CTL and create a signed message containing the encoded CTL.
  6176. //--------------------------------------------------------------------------
  6177. WINCRYPT32API
  6178. BOOL
  6179. WINAPI
  6180. CryptMsgEncodeAndSignCTL(
  6181.     IN DWORD dwMsgEncodingType,
  6182.     IN PCTL_INFO pCtlInfo,
  6183.     IN PCMSG_SIGNED_ENCODE_INFO pSignInfo,
  6184.     IN DWORD dwFlags,
  6185.     OUT BYTE *pbEncoded,
  6186.     IN OUT DWORD *pcbEncoded
  6187.     );
  6188.  
  6189.  
  6190. //+=========================================================================
  6191. //  Certificate Verify CTL Usage Data Structures and APIs
  6192. //==========================================================================
  6193.  
  6194. typedef struct _CTL_VERIFY_USAGE_PARA {
  6195.     DWORD                   cbSize;
  6196.     CRYPT_DATA_BLOB         ListIdentifier;     // OPTIONAL
  6197.     DWORD                   cCtlStore;
  6198.     HCERTSTORE              *rghCtlStore;       // OPTIONAL
  6199.     DWORD                   cSignerStore;
  6200.     HCERTSTORE              *rghSignerStore;    // OPTIONAL
  6201. } CTL_VERIFY_USAGE_PARA, *PCTL_VERIFY_USAGE_PARA;
  6202.  
  6203. typedef struct _CTL_VERIFY_USAGE_STATUS {
  6204.     DWORD                   cbSize;
  6205.     DWORD                   dwError;
  6206.     DWORD                   dwFlags;
  6207.     PCCTL_CONTEXT           *ppCtl;             // IN OUT OPTIONAL
  6208.     DWORD                   dwCtlEntryIndex;
  6209.     PCCERT_CONTEXT          *ppSigner;          // IN OUT OPTIONAL
  6210.     DWORD                   dwSignerIndex;
  6211. } CTL_VERIFY_USAGE_STATUS, *PCTL_VERIFY_USAGE_STATUS;
  6212.  
  6213. #define CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG     0x1
  6214. #define CERT_VERIFY_TRUSTED_SIGNERS_FLAG        0x2
  6215. #define CERT_VERIFY_NO_TIME_CHECK_FLAG          0x4
  6216. #define CERT_VERIFY_ALLOW_MORE_USAGE_FLAG       0x8
  6217.  
  6218. #define CERT_VERIFY_UPDATED_CTL_FLAG            0x1
  6219.  
  6220. //+-------------------------------------------------------------------------
  6221. //  Verify that a subject is trusted for the specified usage by finding a
  6222. //  signed and time valid CTL with the usage identifiers and containing the
  6223. //  the subject. A subject can be identified by either its certificate context
  6224. //  or any identifier such as its SHA1 hash.
  6225. //
  6226. //  See CertFindSubjectInCTL for definition of dwSubjectType and pvSubject
  6227. //  parameters.
  6228. //
  6229. //  Via pVerifyUsagePara, the caller can specify the stores to be searched
  6230. //  to find the CTL. The caller can also specify the stores containing
  6231. //  acceptable CTL signers. By setting the ListIdentifier, the caller
  6232. //  can also restrict to a particular signer CTL list.
  6233. //
  6234. //  Via pVerifyUsageStatus, the CTL containing the subject, the subject's
  6235. //  index into the CTL's array of entries, and the signer of the CTL
  6236. //  are returned. If the caller is not interested, ppCtl and ppSigner can be set
  6237. //  to NULL. Returned contexts must be freed via the store's free context APIs.
  6238. //
  6239. //  If the CERT_VERIFY_INHIBIT_CTL_UPDATE_FLAG isn't set, then, a time
  6240. //  invalid CTL in one of the CtlStores may be replaced. When replaced, the
  6241. //  CERT_VERIFY_UPDATED_CTL_FLAG is set in pVerifyUsageStatus->dwFlags.
  6242. //
  6243. //  If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the
  6244. //  SignerStores specified in pVerifyUsageStatus are searched to find
  6245. //  the signer. Otherwise, the SignerStores provide additional sources
  6246. //  to find the signer's certificate.
  6247. //
  6248. //  If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked
  6249. //  for time validity.
  6250. //
  6251. //  If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain
  6252. //  additional usage identifiers than specified by pSubjectUsage. Otherwise,
  6253. //  the found CTL will contain the same usage identifers and no more.
  6254. //
  6255. //  CertVerifyCTLUsage will be implemented as a dispatcher to OID installable
  6256. //  functions. First, it will try to find an OID function matching the first
  6257. //  usage object identifier in the pUsage sequence. Next, it will dispatch
  6258. //  to the default CertDllVerifyCTLUsage functions.
  6259. //
  6260. //  If the subject is trusted for the specified usage, then, TRUE is
  6261. //  returned. Otherwise, FALSE is returned with dwError set to one of the
  6262. //  following:
  6263. //      CRYPT_E_NO_VERIFY_USAGE_DLL
  6264. //      CRYPT_E_NO_VERIFY_USAGE_CHECK
  6265. //      CRYPT_E_VERIFY_USAGE_OFFLINE
  6266. //      CRYPT_E_NOT_IN_CTL
  6267. //      CRYPT_E_NO_TRUSTED_SIGNER
  6268. //--------------------------------------------------------------------------
  6269. WINCRYPT32API
  6270. BOOL
  6271. WINAPI
  6272. CertVerifyCTLUsage(
  6273.     IN DWORD dwEncodingType,
  6274.     IN DWORD dwSubjectType,
  6275.     IN void *pvSubject,
  6276.     IN PCTL_USAGE pSubjectUsage,
  6277.     IN DWORD dwFlags,
  6278.     IN OPTIONAL PCTL_VERIFY_USAGE_PARA pVerifyUsagePara,
  6279.     IN OUT PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus
  6280.     );
  6281.  
  6282.  
  6283. //+=========================================================================
  6284. //  Certificate Revocation Data Structures and APIs
  6285. //==========================================================================
  6286.  
  6287. //+-------------------------------------------------------------------------
  6288. //  The following data structure may be passed to CertVerifyRevocation to
  6289. //  assist in finding the issuer of the context to be verified.
  6290. //
  6291. //  When pIssuerCert is specified, pIssuerCert is the issuer of
  6292. //  rgpvContext[cContext - 1].
  6293. //
  6294. //  When cCertStore and rgCertStore are specified, these stores may contain
  6295. //  an issuer certificate.
  6296. //--------------------------------------------------------------------------
  6297. typedef struct _CERT_REVOCATION_PARA {
  6298.     DWORD                   cbSize;
  6299.     PCCERT_CONTEXT          pIssuerCert;
  6300.     DWORD                   cCertStore;
  6301.     HCERTSTORE              *rgCertStore;
  6302. } CERT_REVOCATION_PARA, *PCERT_REVOCATION_PARA;
  6303.  
  6304.  
  6305. //+-------------------------------------------------------------------------
  6306. //  The following data structure is returned by CertVerifyRevocation to
  6307. //  specify the status of the revoked or unchecked context. Review the
  6308. //  following CertVerifyRevocation comments for details.
  6309. //
  6310. //  Upon input to CertVerifyRevocation, cbSize must be set to a size
  6311. //  >= sizeof(CERT_REVOCATION_STATUS). Otherwise, CertVerifyRevocation
  6312. //  returns FALSE and sets LastError to E_INVALIDARG.
  6313. //
  6314. //  Upon input to the installed or registered CRYPT_OID_VERIFY_REVOCATION_FUNC
  6315. //  functions, the dwIndex, dwError and dwReason have been zero'ed.
  6316. //--------------------------------------------------------------------------
  6317. typedef struct _CERT_REVOCATION_STATUS {
  6318.     DWORD                   cbSize;
  6319.     DWORD                   dwIndex;
  6320.     DWORD                   dwError;
  6321.     DWORD                   dwReason;
  6322. } CERT_REVOCATION_STATUS, *PCERT_REVOCATION_STATUS;
  6323.  
  6324.  
  6325. //+-------------------------------------------------------------------------
  6326. //  Verifies the array of contexts for revocation. The dwRevType parameter
  6327. //  indicates the type of the context data structure passed in rgpvContext.
  6328. //  Currently only the revocation of certificates is defined.
  6329. //
  6330. //  If the CERT_VERIFY_REV_CHAIN_FLAG flag is set, then, CertVerifyRevocation
  6331. //  is verifying a chain of certs where, rgpvContext[i + 1] is the issuer
  6332. //  of rgpvContext[i]. Otherwise, CertVerifyRevocation makes no assumptions
  6333. //  about the order of the contexts.
  6334. //
  6335. //  To assist in finding the issuer, the pRevPara may optionally be set. See
  6336. //  the CERT_REVOCATION_PARA data structure for details.
  6337. //
  6338. //  The contexts must contain enough information to allow the
  6339. //  installable or registered revocation DLLs to find the revocation server. For
  6340. //  certificates, this information would normally be conveyed in an
  6341. //  extension such as the IETF's AuthorityInfoAccess extension.
  6342. //
  6343. //  CertVerifyRevocation returns TRUE if all of the contexts were successfully
  6344. //  checked and none were revoked. Otherwise, returns FALSE and updates the
  6345. //  returned pRevStatus data structure as follows:
  6346. //    dwIndex
  6347. //      Index of the first context that was revoked or unable to
  6348. //      be checked for revocation
  6349. //    dwError
  6350. //      Error status. LastError is also set to this error status.
  6351. //      dwError can be set to one of the following error codes defined
  6352. //      in winerror.h:
  6353. //        ERROR_SUCCESS - good context
  6354. //        CRYPT_E_REVOKED - context was revoked. dwReason contains the
  6355. //           reason for revocation
  6356. //        CRYPT_E_REVOCATION_OFFLINE - unable to connect to the
  6357. //           revocation server
  6358. //        CRYPT_E_NOT_IN_REVOCATION_DATABASE - the context to be checked
  6359. //           was not found in the revocation server's database.
  6360. //        CRYPT_E_NO_REVOCATION_CHECK - the called revocation function
  6361. //           wasn't able to do a revocation check on the context
  6362. //        CRYPT_E_NO_REVOCATION_DLL - no installed or registered Dll was
  6363. //           found to verify revocation
  6364. //    dwReason
  6365. //      The dwReason is currently only set for CRYPT_E_REVOKED and contains
  6366. //      the reason why the context was revoked. May be one of the following
  6367. //      CRL reasons defined by the CRL Reason Code extension ("2.5.29.21")
  6368. //          CRL_REASON_UNSPECIFIED              0
  6369. //          CRL_REASON_KEY_COMPROMISE           1
  6370. //          CRL_REASON_CA_COMPROMISE            2
  6371. //          CRL_REASON_AFFILIATION_CHANGED      3
  6372. //          CRL_REASON_SUPERSEDED               4
  6373. //          CRL_REASON_CESSATION_OF_OPERATION   5
  6374. //          CRL_REASON_CERTIFICATE_HOLD         6
  6375. //
  6376. //  For each entry in rgpvContext, CertVerifyRevocation iterates
  6377. //  through the CRYPT_OID_VERIFY_REVOCATION_FUNC
  6378. //  function set's list of installed DEFAULT functions.
  6379. //  CryptGetDefaultOIDFunctionAddress is called with pwszDll = NULL. If no
  6380. //  installed functions are found capable of doing the revocation verification,
  6381. //  CryptVerifyRevocation iterates through CRYPT_OID_VERIFY_REVOCATION_FUNC's
  6382. //  list of registered DEFAULT Dlls. CryptGetDefaultOIDDllList is called to
  6383. //  get the list. CryptGetDefaultOIDFunctionAddress is called to load the Dll.
  6384. //
  6385. //  The called functions have the same signature as CertVerifyRevocation. A
  6386. //  called function returns TRUE if it was able to successfully check all of
  6387. //  the contexts and none were revoked. Otherwise, the called function returns
  6388. //  FALSE and updates pRevStatus. dwIndex is set to the index of
  6389. //  the first context that was found to be revoked or unable to be checked.
  6390. //  dwError and LastError are updated. For CRYPT_E_REVOKED, dwReason
  6391. //  is updated. Upon input to the called function, dwIndex, dwError and
  6392. //  dwReason have been zero'ed. cbSize has been checked to be >=
  6393. //  sizeof(CERT_REVOCATION_STATUS).
  6394. //
  6395. //  If the called function returns FALSE, and dwError isn't set to
  6396. //  CRYPT_E_REVOKED, then, CertVerifyRevocation either continues on to the
  6397. //  next DLL in the list for a returned dwIndex of 0 or for a returned
  6398. //  dwIndex > 0, restarts the process of finding a verify function by
  6399. //  advancing the start of the context array to the returned dwIndex and
  6400. //  decrementing the count of remaining contexts.
  6401. //--------------------------------------------------------------------------
  6402. WINCRYPT32API
  6403. BOOL
  6404. WINAPI
  6405. CertVerifyRevocation(
  6406.     IN DWORD dwEncodingType,
  6407.     IN DWORD dwRevType,
  6408.     IN DWORD cContext,
  6409.     IN PVOID rgpvContext[],
  6410.     IN DWORD dwFlags,
  6411.     IN OPTIONAL PCERT_REVOCATION_PARA pRevPara,
  6412.     IN OUT PCERT_REVOCATION_STATUS pRevStatus
  6413.     );
  6414.  
  6415. //+-------------------------------------------------------------------------
  6416. //  Revocation types
  6417. //--------------------------------------------------------------------------
  6418. #define CERT_CONTEXT_REVOCATION_TYPE        1
  6419.  
  6420. //+-------------------------------------------------------------------------
  6421. //  When the following flag is set, rgpvContext[] consists of a chain
  6422. //  of certificates, where rgpvContext[i + 1] is the issuer of rgpvContext[i].
  6423. //--------------------------------------------------------------------------
  6424. #define CERT_VERIFY_REV_CHAIN_FLAG          0x1
  6425.  
  6426. //+-------------------------------------------------------------------------
  6427. //  CERT_CONTEXT_REVOCATION_TYPE
  6428. //
  6429. //  pvContext points to a const CERT_CONTEXT.
  6430. //--------------------------------------------------------------------------
  6431.  
  6432. //+=========================================================================
  6433. //  Certificate Helper APIs
  6434. //==========================================================================
  6435.  
  6436.  
  6437. //+-------------------------------------------------------------------------
  6438. //  Compare two multiple byte integer blobs to see if they are identical.
  6439. //
  6440. //  Before doing the comparison, leading zero bytes are removed from a
  6441. //  positive number and leading 0xFF bytes are removed from a negative
  6442. //  number.
  6443. //
  6444. //  The multiple byte integers are treated as Little Endian. pbData[0] is the
  6445. //  least significant byte and pbData[cbData - 1] is the most significant
  6446. //  byte.
  6447. //
  6448. //  Returns TRUE if the integer blobs are identical after removing leading
  6449. //  0 or 0xFF bytes.
  6450. //--------------------------------------------------------------------------
  6451. BOOL
  6452. WINAPI
  6453. CertCompareIntegerBlob(
  6454.     IN PCRYPT_INTEGER_BLOB pInt1,
  6455.     IN PCRYPT_INTEGER_BLOB pInt2
  6456.     );
  6457.  
  6458. //+-------------------------------------------------------------------------
  6459. //  Compare two certificates to see if they are identical.
  6460. //
  6461. //  Since a certificate is uniquely identified by its Issuer and SerialNumber,
  6462. //  these are the only fields needing to be compared.
  6463. //
  6464. //  Returns TRUE if the certificates are identical.
  6465. //--------------------------------------------------------------------------
  6466. WINCRYPT32API
  6467. BOOL
  6468. WINAPI
  6469. CertCompareCertificate(
  6470.     IN DWORD dwCertEncodingType,
  6471.     IN PCERT_INFO pCertId1,
  6472.     IN PCERT_INFO pCertId2
  6473.     );
  6474.  
  6475. //+-------------------------------------------------------------------------
  6476. //  Compare two certificate names to see if they are identical.
  6477. //
  6478. //  Returns TRUE if the names are identical.
  6479. //--------------------------------------------------------------------------
  6480. WINCRYPT32API
  6481. BOOL
  6482. WINAPI
  6483. CertCompareCertificateName(
  6484.     IN DWORD dwCertEncodingType,
  6485.     IN PCERT_NAME_BLOB pCertName1,
  6486.     IN PCERT_NAME_BLOB pCertName2
  6487.     );
  6488.  
  6489. //+-------------------------------------------------------------------------
  6490. //  Compare the attributes in the certificate name with the specified
  6491. //  Relative Distinguished Name's (CERT_RDN) array of attributes.
  6492. //  The comparison iterates through the CERT_RDN attributes and looks for an
  6493. //  attribute match in any of the certificate name's RDNs.
  6494. //  Returns TRUE if all the attributes are found and match.
  6495. //
  6496. //  The CERT_RDN_ATTR fields can have the following special values:
  6497. //    pszObjId == NULL              - ignore the attribute object identifier
  6498. //    dwValueType == RDN_ANY_TYPE   - ignore the value type
  6499. //
  6500. //  Currently only an exact, case sensitive match is supported.
  6501. //
  6502. //  CERT_UNICODE_IS_RDN_ATTRS_FLAG should be set if the pRDN was initialized
  6503. //  with unicode strings as for CryptEncodeObject(X509_UNICODE_NAME).
  6504. //--------------------------------------------------------------------------
  6505. WINCRYPT32API
  6506. BOOL
  6507. WINAPI
  6508. CertIsRDNAttrsInCertificateName(
  6509.     IN DWORD dwCertEncodingType,
  6510.     IN DWORD dwFlags,
  6511.     IN PCERT_NAME_BLOB pCertName,
  6512.     IN PCERT_RDN pRDN
  6513.     );
  6514.  
  6515. #define CERT_UNICODE_IS_RDN_ATTRS_FLAG  0x1
  6516.  
  6517. //+-------------------------------------------------------------------------
  6518. //  Compare two public keys to see if they are identical.
  6519. //
  6520. //  Returns TRUE if the keys are identical.
  6521. //--------------------------------------------------------------------------
  6522. WINCRYPT32API
  6523. BOOL
  6524. WINAPI
  6525. CertComparePublicKeyInfo(
  6526.     IN DWORD dwCertEncodingType,
  6527.     IN PCERT_PUBLIC_KEY_INFO pPublicKey1,
  6528.     IN PCERT_PUBLIC_KEY_INFO pPublicKey2
  6529.     );
  6530.  
  6531. //+-------------------------------------------------------------------------
  6532. //  Get the public/private key's bit length.
  6533. //
  6534. //  Returns 0 if unable to determine the key's length.
  6535. //--------------------------------------------------------------------------
  6536. WINCRYPT32API
  6537. DWORD
  6538. WINAPI
  6539. CertGetPublicKeyLength(
  6540.     IN DWORD dwCertEncodingType,
  6541.     IN PCERT_PUBLIC_KEY_INFO pPublicKey
  6542.     );
  6543.  
  6544. //+-------------------------------------------------------------------------
  6545. //  Verify the signature of a subject certificate or a CRL using the
  6546. //  public key info
  6547. //
  6548. //  Returns TRUE for a valid signature.
  6549. //
  6550. //  hCryptProv specifies the crypto provider to use to verify the signature.
  6551. //  It doesn't need to use a private key.
  6552. //--------------------------------------------------------------------------
  6553. WINCRYPT32API
  6554. BOOL
  6555. WINAPI
  6556. CryptVerifyCertificateSignature(
  6557.     IN HCRYPTPROV               hCryptProv,
  6558.     IN DWORD                    dwCertEncodingType,
  6559.     IN const BYTE *             pbEncoded,
  6560.     IN DWORD                    cbEncoded,
  6561.     IN PCERT_PUBLIC_KEY_INFO    pPublicKey
  6562.     );
  6563.  
  6564. //+-------------------------------------------------------------------------
  6565. //  Compute the hash of the "to be signed" information in the encoded
  6566. //  signed content (CERT_SIGNED_CONTENT_INFO).
  6567. //
  6568. //  hCryptProv specifies the crypto provider to use to compute the hash.
  6569. //  It doesn't need to use a private key.
  6570. //--------------------------------------------------------------------------
  6571. WINCRYPT32API
  6572. BOOL
  6573. WINAPI
  6574. CryptHashToBeSigned(
  6575.     IN HCRYPTPROV hCryptProv,
  6576.     IN DWORD dwCertEncodingType,
  6577.     IN const BYTE *pbEncoded,
  6578.     IN DWORD cbEncoded,
  6579.     OUT BYTE *pbComputedHash,
  6580.     IN OUT DWORD *pcbComputedHash
  6581.     );
  6582.  
  6583. //+-------------------------------------------------------------------------
  6584. //  Hash the encoded content.
  6585. //
  6586. //  hCryptProv specifies the crypto provider to use to compute the hash.
  6587. //  It doesn't need to use a private key.
  6588. //
  6589. //  Algid specifies the CAPI hash algorithm to use. If Algid is 0, then, the
  6590. //  default hash algorithm (currently SHA1) is used.
  6591. //--------------------------------------------------------------------------
  6592. WINCRYPT32API
  6593. BOOL
  6594. WINAPI
  6595. CryptHashCertificate(
  6596.     IN HCRYPTPROV hCryptProv,
  6597.     IN ALG_ID Algid,
  6598.     IN DWORD dwFlags,
  6599.     IN const BYTE *pbEncoded,
  6600.     IN DWORD cbEncoded,
  6601.     OUT BYTE *pbComputedHash,
  6602.     IN OUT DWORD *pcbComputedHash
  6603.     );
  6604.  
  6605. //+-------------------------------------------------------------------------
  6606. //  Sign the "to be signed" information in the encoded signed content.
  6607. //
  6608. //  hCryptProv specifies the crypto provider to use to do the signature.
  6609. //  It uses the specified private key.
  6610. //--------------------------------------------------------------------------
  6611. WINCRYPT32API
  6612. BOOL
  6613. WINAPI
  6614. CryptSignCertificate(
  6615.     IN HCRYPTPROV hCryptProv,
  6616.     IN DWORD dwKeySpec,
  6617.     IN DWORD dwCertEncodingType,
  6618.     IN const BYTE *pbEncodedToBeSigned,
  6619.     IN DWORD cbEncodedToBeSigned,
  6620.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  6621.     IN OPTIONAL const void *pvHashAuxInfo,
  6622.     OUT BYTE *pbSignature,
  6623.     IN OUT DWORD *pcbSignature
  6624.     );
  6625.  
  6626. //+-------------------------------------------------------------------------
  6627. //  Encode the "to be signed" information. Sign the encoded "to be signed".
  6628. //  Encode the "to be signed" and the signature.
  6629. //
  6630. //  hCryptProv specifies the crypto provider to use to do the signature.
  6631. //  It uses the specified private key.
  6632. //--------------------------------------------------------------------------
  6633. WINCRYPT32API
  6634. BOOL
  6635. WINAPI
  6636. CryptSignAndEncodeCertificate(
  6637.     IN HCRYPTPROV hCryptProv,
  6638.     IN DWORD dwKeySpec,
  6639.     IN DWORD dwCertEncodingType,
  6640.     IN LPCSTR lpszStructType,       // "to be signed"
  6641.     IN const void *pvStructInfo,
  6642.     IN PCRYPT_ALGORITHM_IDENTIFIER pSignatureAlgorithm,
  6643.     IN OPTIONAL const void *pvHashAuxInfo,
  6644.     OUT PBYTE pbEncoded,
  6645.     IN OUT DWORD *pcbEncoded
  6646.     );
  6647.  
  6648.  
  6649. //+-------------------------------------------------------------------------
  6650. //  Verify the time validity of a certificate.
  6651. //
  6652. //  Returns -1 if before NotBefore, +1 if after NotAfter and otherwise 0 for
  6653. //  a valid certificate
  6654. //
  6655. //  If pTimeToVerify is NULL, uses the current time.
  6656. //--------------------------------------------------------------------------
  6657. WINCRYPT32API
  6658. LONG
  6659. WINAPI
  6660. CertVerifyTimeValidity(
  6661.     IN LPFILETIME pTimeToVerify,
  6662.     IN PCERT_INFO pCertInfo
  6663.     );
  6664.  
  6665.  
  6666. //+-------------------------------------------------------------------------
  6667. //  Verify the time validity of a CRL.
  6668. //
  6669. //  Returns -1 if before ThisUpdate, +1 if after NextUpdate and otherwise 0 for
  6670. //  a valid CRL
  6671. //
  6672. //  If pTimeToVerify is NULL, uses the current time.
  6673. //--------------------------------------------------------------------------
  6674. WINCRYPT32API
  6675. LONG
  6676. WINAPI
  6677. CertVerifyCRLTimeValidity(
  6678.     IN LPFILETIME pTimeToVerify,
  6679.     IN PCRL_INFO pCrlInfo
  6680.     );
  6681.  
  6682. //+-------------------------------------------------------------------------
  6683. //  Verify that the subject's time validity nests within the issuer's time
  6684. //  validity.
  6685. //
  6686. //  Returns TRUE if it nests. Otherwise, returns FALSE.
  6687. //--------------------------------------------------------------------------
  6688. WINCRYPT32API
  6689. BOOL
  6690. WINAPI
  6691. CertVerifyValidityNesting(
  6692.     IN PCERT_INFO pSubjectInfo,
  6693.     IN PCERT_INFO pIssuerInfo
  6694.     );
  6695.  
  6696. //+-------------------------------------------------------------------------
  6697. //  Verify that the subject certificate isn't on its issuer CRL.
  6698. //
  6699. //  Returns true if the certificate isn't on the CRL.
  6700. //--------------------------------------------------------------------------
  6701. WINCRYPT32API
  6702. BOOL
  6703. WINAPI
  6704. CertVerifyCRLRevocation(
  6705.     IN DWORD dwCertEncodingType,
  6706.     IN PCERT_INFO pCertId,          // Only the Issuer and SerialNumber
  6707.                                     // fields are used
  6708.     IN DWORD cCrlInfo,
  6709.     IN PCRL_INFO rgpCrlInfo[]
  6710.     );
  6711.  
  6712. //+-------------------------------------------------------------------------
  6713. //  Convert the CAPI AlgId to the ASN.1 Object Identifier string
  6714. //
  6715. //  Returns NULL if there isn't an ObjId corresponding to the AlgId.
  6716. //--------------------------------------------------------------------------
  6717. WINCRYPT32API
  6718. LPCSTR
  6719. WINAPI
  6720. CertAlgIdToOID(
  6721.     IN DWORD dwAlgId
  6722.     );
  6723.  
  6724. //+-------------------------------------------------------------------------
  6725. //  Convert the ASN.1 Object Identifier string to the CAPI AlgId.
  6726. //
  6727. //  Returns 0 if there isn't an AlgId corresponding to the ObjId.
  6728. //--------------------------------------------------------------------------
  6729. WINCRYPT32API
  6730. DWORD
  6731. WINAPI
  6732. CertOIDToAlgId(
  6733.     IN LPCSTR pszObjId
  6734.     );
  6735.  
  6736. //+-------------------------------------------------------------------------
  6737. //  Find an extension identified by its Object Identifier.
  6738. //
  6739. //  If found, returns pointer to the extension. Otherwise, returns NULL.
  6740. //--------------------------------------------------------------------------
  6741. WINCRYPT32API
  6742. PCERT_EXTENSION
  6743. WINAPI
  6744. CertFindExtension(
  6745.     IN LPCSTR pszObjId,
  6746.     IN DWORD cExtensions,
  6747.     IN CERT_EXTENSION rgExtensions[]
  6748.     );
  6749.  
  6750. //+-------------------------------------------------------------------------
  6751. //  Find the first attribute identified by its Object Identifier.
  6752. //
  6753. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  6754. //--------------------------------------------------------------------------
  6755. WINCRYPT32API
  6756. PCRYPT_ATTRIBUTE
  6757. WINAPI
  6758. CertFindAttribute(
  6759.     IN LPCSTR pszObjId,
  6760.     IN DWORD cAttr,
  6761.     IN CRYPT_ATTRIBUTE rgAttr[]
  6762.     );
  6763.  
  6764. //+-------------------------------------------------------------------------
  6765. //  Find the first CERT_RDN attribute identified by its Object Identifier in
  6766. //  the name's list of Relative Distinguished Names.
  6767. //
  6768. //  If found, returns pointer to the attribute. Otherwise, returns NULL.
  6769. //--------------------------------------------------------------------------
  6770. WINCRYPT32API
  6771. PCERT_RDN_ATTR
  6772. WINAPI
  6773. CertFindRDNAttr(
  6774.     IN LPCSTR pszObjId,
  6775.     IN PCERT_NAME_INFO pName
  6776.     );
  6777.  
  6778. //+-------------------------------------------------------------------------
  6779. //  Get the intended key usage bytes from the certificate.
  6780. //
  6781. //  If the certificate doesn't have any intended key usage bytes, returns FALSE
  6782. //  and *pbKeyUsage is zeroed. Otherwise, returns TRUE and up through
  6783. //  cbKeyUsage bytes are copied into *pbKeyUsage. Any remaining uncopied
  6784. //  bytes are zeroed.
  6785. //--------------------------------------------------------------------------
  6786. WINCRYPT32API
  6787. BOOL
  6788. WINAPI
  6789. CertGetIntendedKeyUsage(
  6790.     IN DWORD dwCertEncodingType,
  6791.     IN PCERT_INFO pCertInfo,
  6792.     OUT BYTE *pbKeyUsage,
  6793.     IN DWORD cbKeyUsage
  6794.     );
  6795.  
  6796.  
  6797. //+-------------------------------------------------------------------------
  6798. //  Export the public key info associated with the provider's corresponding
  6799. //  private key.
  6800. //
  6801. //  Calls CryptExportPublicKeyInfo with pszPublicKeyObjId = szOID_RSA_RSA,
  6802. //  dwFlags = 0 and pvAuxInfo = NULL.
  6803. //--------------------------------------------------------------------------
  6804. WINCRYPT32API
  6805. BOOL
  6806. WINAPI
  6807. CryptExportPublicKeyInfo(
  6808.     IN HCRYPTPROV hCryptProv,
  6809.     IN DWORD dwKeySpec,
  6810.     IN DWORD dwCertEncodingType,
  6811.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  6812.     IN OUT DWORD *pcbInfo
  6813.     );
  6814.  
  6815.  
  6816. //+-------------------------------------------------------------------------
  6817. //  Export the public key info associated with the provider's corresponding
  6818. //  private key.
  6819. //
  6820. //  Uses the dwCertEncodingType and pszPublicKeyObjId to call the
  6821. //  installable CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC. The called function
  6822. //  has the same signature as CryptExportPublicKeyInfoEx.
  6823. //
  6824. //  If unable to find an installable OID function for the pszPublicKeyObjId,
  6825. //  attempts to export as a RSA Public Key (szOID_RSA_RSA).
  6826. //
  6827. //  The dwFlags and pvAuxInfo aren't used for szOID_RSA_RSA.
  6828. //--------------------------------------------------------------------------
  6829. #define CRYPT_OID_EXPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllExportPublicKeyInfoEx"
  6830.  
  6831. WINCRYPT32API
  6832. BOOL
  6833. WINAPI
  6834. CryptExportPublicKeyInfoEx(
  6835.     IN HCRYPTPROV hCryptProv,
  6836.     IN DWORD dwKeySpec,
  6837.     IN DWORD dwCertEncodingType,
  6838.     IN LPSTR pszPublicKeyObjId,
  6839.     IN DWORD dwFlags,
  6840.     IN OPTIONAL void *pvAuxInfo,
  6841.     OUT PCERT_PUBLIC_KEY_INFO pInfo,
  6842.     IN OUT DWORD *pcbInfo
  6843.     );
  6844.  
  6845.  
  6846. //+-------------------------------------------------------------------------
  6847. //  Convert and import the public key info into the provider and return a
  6848. //  handle to the public key.
  6849. //
  6850. //  Calls CryptImportPublicKeyInfoEx with aiKeyAlg = 0, dwFlags = 0 and
  6851. //  pvAuxInfo = NULL.
  6852. //--------------------------------------------------------------------------
  6853. WINCRYPT32API
  6854. BOOL
  6855. WINAPI
  6856. CryptImportPublicKeyInfo(
  6857.     IN HCRYPTPROV hCryptProv,
  6858.     IN DWORD dwCertEncodingType,
  6859.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6860.     OUT HCRYPTKEY *phKey
  6861.     );
  6862.  
  6863. //+-------------------------------------------------------------------------
  6864. //  Convert and import the public key info into the provider and return a
  6865. //  handle to the public key.
  6866. //
  6867. //  Uses the dwCertEncodingType and pInfo->Algorithm.pszObjId to call the
  6868. //  installable CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC. The called function
  6869. //  has the same signature as CryptImportPublicKeyInfoEx.
  6870. //
  6871. //  If unable to find an installable OID function for the pszObjId,
  6872. //  attempts to import as a RSA Public Key (szOID_RSA_RSA).
  6873. //
  6874. //  For szOID_RSA_RSA: aiKeyAlg may be set to CALG_RSA_SIGN or CALG_RSA_KEYX.
  6875. //  Defaults to CALG_RSA_KEYX. The dwFlags and pvAuxInfo aren't used.
  6876. //--------------------------------------------------------------------------
  6877. #define CRYPT_OID_IMPORT_PUBLIC_KEY_INFO_FUNC   "CryptDllImportPublicKeyInfoEx"
  6878.  
  6879. WINCRYPT32API
  6880. BOOL
  6881. WINAPI
  6882. CryptImportPublicKeyInfoEx(
  6883.     IN HCRYPTPROV hCryptProv,
  6884.     IN DWORD dwCertEncodingType,
  6885.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6886.     IN ALG_ID aiKeyAlg,
  6887.     IN DWORD dwFlags,
  6888.     IN OPTIONAL void *pvAuxInfo,
  6889.     OUT HCRYPTKEY *phKey
  6890.     );
  6891.  
  6892. //+-------------------------------------------------------------------------
  6893. //  Compute the hash of the encoded public key info.
  6894. //
  6895. //  The public key info is encoded and then hashed.
  6896. //--------------------------------------------------------------------------
  6897. WINCRYPT32API
  6898. BOOL
  6899. WINAPI
  6900. CryptHashPublicKeyInfo(
  6901.     IN HCRYPTPROV hCryptProv,
  6902.     IN ALG_ID Algid,
  6903.     IN DWORD dwFlags,
  6904.     IN DWORD dwCertEncodingType,
  6905.     IN PCERT_PUBLIC_KEY_INFO pInfo,
  6906.     OUT BYTE *pbComputedHash,
  6907.     IN OUT DWORD *pcbComputedHash
  6908.     );
  6909.  
  6910. //+-------------------------------------------------------------------------
  6911. //  Convert a Name Value to a null terminated char string
  6912. //
  6913. //  Returns the number of characters converted including the terminating null
  6914. //  character. If psz is NULL or csz is 0, returns the required size of the
  6915. //  destination string (including the terminating null char).
  6916. //
  6917. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  6918. //
  6919. //  Note: csz includes the NULL char.
  6920. //--------------------------------------------------------------------------
  6921. WINCRYPT32API
  6922. DWORD
  6923. WINAPI
  6924. CertRDNValueToStrA(
  6925.     IN DWORD dwValueType,
  6926.     IN PCERT_RDN_VALUE_BLOB pValue,
  6927.     OUT OPTIONAL LPSTR psz,
  6928.     IN DWORD csz
  6929.     );
  6930. //+-------------------------------------------------------------------------
  6931. //  Convert a Name Value to a null terminated char string
  6932. //
  6933. //  Returns the number of characters converted including the terminating null
  6934. //  character. If psz is NULL or csz is 0, returns the required size of the
  6935. //  destination string (including the terminating null char).
  6936. //
  6937. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  6938. //
  6939. //  Note: csz includes the NULL char.
  6940. //--------------------------------------------------------------------------
  6941. WINCRYPT32API
  6942. DWORD
  6943. WINAPI
  6944. CertRDNValueToStrW(
  6945.     IN DWORD dwValueType,
  6946.     IN PCERT_RDN_VALUE_BLOB pValue,
  6947.     OUT OPTIONAL LPWSTR psz,
  6948.     IN DWORD csz
  6949.     );
  6950. #ifdef UNICODE
  6951. #define CertRDNValueToStr  CertRDNValueToStrW
  6952. #else
  6953. #define CertRDNValueToStr  CertRDNValueToStrA
  6954. #endif // !UNICODE
  6955.  
  6956. //+-------------------------------------------------------------------------
  6957. //  Convert the certificate name blob to a null terminated char string.
  6958. //
  6959. //  Follows the string representation of distinguished names specified in
  6960. //  RFC 1779. (Note, added double quoting "" for embedded quotes, quote
  6961. //  empty strings and don't quote strings containing consecutive spaces).
  6962. //  RDN values of type CERT_RDN_ENCODED_BLOB or CERT_RDN_OCTET_STRING are
  6963. //  formatted in hexadecimal (e.g. #0A56CF).
  6964. //
  6965. //  The name string is formatted according to the dwStrType:
  6966. //    CERT_SIMPLE_NAME_STR
  6967. //      The object identifiers are discarded. CERT_RDN entries are separated
  6968. //      by ", ". Multiple attributes per CERT_RDN are separated by " + ".
  6969. //      For example:
  6970. //          Microsoft, Joe Cool + Programmer
  6971. //    CERT_OID_NAME_STR
  6972. //      The object identifiers are included with a "=" separator from their
  6973. //      attribute value. CERT_RDN entries are separated by ", ".
  6974. //      Multiple attributes per CERT_RDN are separated by " + ". For example:
  6975. //          2.5.4.11=Microsoft, 2.5.4.3=Joe Cool + 2.5.4.12=Programmer
  6976. //    CERT_X500_NAME_STR
  6977. //      The object identifiers are converted to their X500 key name. Otherwise,
  6978. //      same as CERT_OID_NAME_STR. If the object identifier doesn't have
  6979. //      a corresponding X500 key name, then, the object identifier is used with
  6980. //      a "OID." prefix. For example:
  6981. //          OU=Microsoft, CN=Joe Cool + T=Programmer, OID.1.2.3.4.5.6=Unknown
  6982. //
  6983. //  We quote the RDN value if it contains leading or trailing whitespace
  6984. //  or one of the following characters: ",", "+", "=", """, "\n",  "<", ">",
  6985. //  "#" or ";". The quoting character is ". If the the RDN Value contains
  6986. //  a " it is double quoted (""). For example:
  6987. //      OU="  Microsoft", CN="Joe ""Cool""" + T="Programmer, Manager"
  6988. //
  6989. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to replace
  6990. //  the ", " separator with a "; " separator.
  6991. //
  6992. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to replace
  6993. //  the ", " separator with a "\r\n" separator.
  6994. //
  6995. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to replace the
  6996. //  " + " separator with a single space, " ".
  6997. //
  6998. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  6999. //  the above quoting.
  7000. //
  7001. //  Returns the number of characters converted including the terminating null
  7002. //  character. If psz is NULL or csz is 0, returns the required size of the
  7003. //  destination string (including the terminating null char).
  7004. //
  7005. //  If psz != NULL && csz != 0, returned psz is always NULL terminated.
  7006. //
  7007. //  Note: csz includes the NULL char.
  7008. //--------------------------------------------------------------------------
  7009.  
  7010. //+-------------------------------------------------------------------------
  7011. //--------------------------------------------------------------------------
  7012. WINCRYPT32API
  7013. DWORD
  7014. WINAPI
  7015. CertNameToStrA(
  7016.     IN DWORD dwCertEncodingType,
  7017.     IN PCERT_NAME_BLOB pName,
  7018.     IN DWORD dwStrType,
  7019.     OUT OPTIONAL LPSTR psz,
  7020.     IN DWORD csz
  7021.     );
  7022. //+-------------------------------------------------------------------------
  7023. //--------------------------------------------------------------------------
  7024. WINCRYPT32API
  7025. DWORD
  7026. WINAPI
  7027. CertNameToStrW(
  7028.     IN DWORD dwCertEncodingType,
  7029.     IN PCERT_NAME_BLOB pName,
  7030.     IN DWORD dwStrType,
  7031.     OUT OPTIONAL LPWSTR psz,
  7032.     IN DWORD csz
  7033.     );
  7034. #ifdef UNICODE
  7035. #define CertNameToStr  CertNameToStrW
  7036. #else
  7037. #define CertNameToStr  CertNameToStrA
  7038. #endif // !UNICODE
  7039.  
  7040. //+-------------------------------------------------------------------------
  7041. //  Certificate name string types
  7042. //--------------------------------------------------------------------------
  7043. #define CERT_SIMPLE_NAME_STR        1
  7044. #define CERT_OID_NAME_STR           2
  7045. #define CERT_X500_NAME_STR          3
  7046.  
  7047. //+-------------------------------------------------------------------------
  7048. //  Certificate name string type flags OR'ed with the above types
  7049. //--------------------------------------------------------------------------
  7050. #define CERT_NAME_STR_SEMICOLON_FLAG    0x40000000
  7051. #define CERT_NAME_STR_NO_PLUS_FLAG      0x20000000
  7052. #define CERT_NAME_STR_NO_QUOTING_FLAG   0x10000000
  7053. #define CERT_NAME_STR_CRLF_FLAG         0x08000000
  7054. #define CERT_NAME_STR_COMMA_FLAG        0x04000000
  7055.  
  7056.  
  7057. //+-------------------------------------------------------------------------
  7058. //  Convert the null terminated X500 string to an encoded certificate name.
  7059. //
  7060. //  The input string is expected to be formatted the same as the output
  7061. //  from the above CertNameToStr API.
  7062. //
  7063. //  The CERT_SIMPLE_NAME_STR type isn't supported. Otherwise, when dwStrType
  7064. //  is set to 0, CERT_OID_NAME_STR or CERT_X500_NAME_STR, allow either a
  7065. //  case insensitive X500 key (CN=), case insensitive "OID." prefixed
  7066. //  object identifier (OID.1.2.3.4.5.6=) or an object identifier (1.2.3.4=).
  7067. //
  7068. //  If no flags are OR'ed into dwStrType, then, allow "," or ";" as RDN
  7069. //  separators and "+" as the multiple RDN value separator. Quoting is
  7070. //  supported. A quote may be included in a quoted value by double quoting,
  7071. //  for example (CN="Joe ""Cool"""). A value starting with a "#" is treated
  7072. //  as ascii hex and converted to a CERT_RDN_OCTET_STRING. Embedded whitespace
  7073. //  is skipped (1.2.3 = # AB CD 01  is the same as 1.2.3=#ABCD01).
  7074. //
  7075. //  Whitespace surrounding the keys, object identifers and values is removed.
  7076. //
  7077. //  CERT_NAME_STR_COMMA_FLAG can be or'ed into dwStrType to only allow the
  7078. //  "," as the RDN separator.
  7079. //
  7080. //  CERT_NAME_STR_SEMICOLON_FLAG can be or'ed into dwStrType to only allow the
  7081. //  ";" as the RDN separator.
  7082. //
  7083. //  CERT_NAME_STR_CRLF_FLAG can be or'ed into dwStrType to only allow
  7084. //  "\r" or "\n" as the RDN separator.
  7085. //
  7086. //  CERT_NAME_STR_NO_PLUS_FLAG can be or'ed into dwStrType to ignore "+"
  7087. //  as a separator and not allow multiple values per RDN.
  7088. //
  7089. //  CERT_NAME_STR_NO_QUOTING_FLAG can be or'ed into dwStrType to inhibit
  7090. //  quoting.
  7091. //
  7092. //  Support the following X500 Keys:
  7093. //
  7094. //  Key         Object Identifier               RDN Value Type(s)
  7095. //  ---         -----------------               -----------------
  7096. //  CN          szOID_COMMON_NAME               Printable, T61
  7097. //  L           szOID_LOCALITY_NAME             Printable, T61
  7098. //  O           szOID_ORGANIZATION_NAME         Printable, T61
  7099. //  OU          szOID_ORGANIZATIONAL_UNIT_NAME  Printable, T61
  7100. //  Email       szOID_RSA_emailAddr             Only IA5
  7101. //  C           szOID_COUNTRY_NAME              Only Printable
  7102. //  S           szOID_STATE_OR_PROVINCE_NAME    Printable, T61
  7103. //  ST          szOID_STATE_OR_PROVINCE_NAME    Printable, T61
  7104. //  STREET      szOID_STREET_ADDRESS            Printable, T61
  7105. //  T           szOID_TITLE                     Printable, T61
  7106. //  Title       szOID_TITLE                     Printable, T61
  7107. //  G           szOID_GIVEN_NAME                Printable, T61
  7108. //  GivenName   szOID_GIVEN_NAME                Printable, T61
  7109. //  I           szOID_INITIALS                  Printable, T61
  7110. //  Initials    szOID_INITIALS                  Printable, T61
  7111. //  SN          szOID_SUR_NAME                  Printable, T61
  7112. //  DC          szOID_DOMAIN_COMPONENT          Only IA5
  7113. //
  7114. //  The T61 types are UTF-8 encoded.
  7115. //
  7116. //  Returns TRUE if successfully parsed the input string and encoded
  7117. //  the name.
  7118. //
  7119. //  If the input string is detected to be invalid, *ppszError is updated
  7120. //  to point to the beginning of the invalid character sequence. Otherwise,
  7121. //  *ppszError is set to NULL. *ppszError is updated with a non-NULL pointer
  7122. //  for the following errors:
  7123. //      CRYPT_E_INVALID_X500_STRING
  7124. //      CRYPT_E_INVALID_NUMERIC_STRING
  7125. //      CRYPT_E_INVALID_PRINTABLE_STRING
  7126. //      CRYPT_E_INVALID_IA5_STRING
  7127. //
  7128. //  ppszError can be set to NULL if not interested in getting a pointer
  7129. //  to the invalid character sequence.
  7130. //--------------------------------------------------------------------------
  7131.  
  7132. //+-------------------------------------------------------------------------
  7133. //--------------------------------------------------------------------------
  7134. WINCRYPT32API
  7135. BOOL
  7136. WINAPI
  7137. CertStrToNameA(
  7138.     IN DWORD dwCertEncodingType,
  7139.     IN LPCSTR pszX500,
  7140.     IN DWORD dwStrType,
  7141.     IN OPTIONAL void *pvReserved,
  7142.     OUT BYTE *pbEncoded,
  7143.     IN OUT DWORD *pcbEncoded,
  7144.     OUT OPTIONAL LPCSTR *ppszError
  7145.     );
  7146. //+-------------------------------------------------------------------------
  7147. //--------------------------------------------------------------------------
  7148. WINCRYPT32API
  7149. BOOL
  7150. WINAPI
  7151. CertStrToNameW(
  7152.     IN DWORD dwCertEncodingType,
  7153.     IN LPCWSTR pszX500,
  7154.     IN DWORD dwStrType,
  7155.     IN OPTIONAL void *pvReserved,
  7156.     OUT BYTE *pbEncoded,
  7157.     IN OUT DWORD *pcbEncoded,
  7158.     OUT OPTIONAL LPCWSTR *ppszError
  7159.     );
  7160. #ifdef UNICODE
  7161. #define CertStrToName  CertStrToNameW
  7162. #else
  7163. #define CertStrToName  CertStrToNameA
  7164. #endif // !UNICODE
  7165.  
  7166.  
  7167. //+=========================================================================
  7168. //  Simplified Cryptographic Message Data Structures and APIs
  7169. //==========================================================================
  7170.  
  7171.  
  7172. //+-------------------------------------------------------------------------
  7173. //              Conventions for the *pb and *pcb output parameters:
  7174. //
  7175. //              Upon entry to the function:
  7176. //                  if pcb is OPTIONAL && pcb == NULL, then,
  7177. //                      No output is returned
  7178. //                  else if pb == NULL && pcb != NULL, then,
  7179. //                      Length only determination. No length error is
  7180. //                      returned.
  7181. //                  otherwise where (pb != NULL && pcb != NULL && *pcb != 0)
  7182. //                      Output is returned. If *pcb isn't big enough a
  7183. //                      length error is returned. In all cases *pcb is updated
  7184. //                      with the actual length needed/returned.
  7185. //--------------------------------------------------------------------------
  7186.  
  7187.  
  7188. //+-------------------------------------------------------------------------
  7189. //  Type definitions of the parameters used for doing the cryptographic
  7190. //  operations.
  7191. //--------------------------------------------------------------------------
  7192.  
  7193. //+-------------------------------------------------------------------------
  7194. //  Callback to get and verify the signer's certificate.
  7195. //
  7196. //  Passed the CertId of the signer (its Issuer and SerialNumber) and a
  7197. //  handle to its cryptographic signed message's cert store.
  7198. //
  7199. //  For CRYPT_E_NO_SIGNER, called with pSignerId == NULL.
  7200. //
  7201. //  For a valid signer certificate, returns a pointer to a read only
  7202. //  CERT_CONTEXT. The returned CERT_CONTEXT is either obtained from a
  7203. //  cert store or was created via CertCreateCertificateContext. For either case,
  7204. //  its freed via CertFreeCertificateContext.
  7205. //
  7206. //  If a valid certificate isn't found, this callback returns NULL with
  7207. //  LastError set via SetLastError().
  7208. //
  7209. //  The NULL implementation tries to get the Signer certificate from the
  7210. //  message cert store. It doesn't verify the certificate.
  7211. //--------------------------------------------------------------------------
  7212. typedef PCCERT_CONTEXT (WINAPI *PFN_CRYPT_GET_SIGNER_CERTIFICATE)(
  7213.             IN void *pvGetArg,
  7214.             IN DWORD dwCertEncodingType,
  7215.             IN PCERT_INFO pSignerId,    // Only the Issuer and SerialNumber
  7216.                                         // fields have been updated
  7217.             IN HCERTSTORE hMsgCertStore
  7218.             );
  7219.  
  7220. //+-------------------------------------------------------------------------
  7221. //  The CRYPT_SIGN_MESSAGE_PARA are used for signing messages using the
  7222. //  specified signing certificate contexts. (Note, allows multiple signers.)
  7223. //
  7224. //  Either the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID must
  7225. //  be set for each rgpSigningCert[]. Either one specifies the private
  7226. //  signature key to use.
  7227. //
  7228. //  If any certificates and/or CRLs are to be included in the signed message,
  7229. //  then, the MsgCert and MsgCrl parameters need to be updated. If the
  7230. //  rgpSigningCerts are to be included, then, they must also be in the
  7231. //  rgpMsgCert array.
  7232. //
  7233. //  cbSize must be set to the sizeof(CRYPT_SIGN_MESSAGE_PARA) or else
  7234. //  LastError will be updated with E_INVALIDARG.
  7235. //
  7236. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7237. //
  7238. //  dwFlags normally is set to 0. However, if the encoded output
  7239. //  is to be a CMSG_SIGNED inner content of an outer cryptographic message,
  7240. //  such as a CMSG_ENVELOPED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  7241. //  should be set. If not set, then it would be encoded as an inner content
  7242. //  type of CMSG_DATA.
  7243. //
  7244. //  dwInnerContentType is normally set to 0. It needs to be set if the
  7245. //  ToBeSigned input is the encoded output of another cryptographic
  7246. //  message, such as, an CMSG_ENVELOPED. When set, it's one of the cryptographic
  7247. //  message types, for example, CMSG_ENVELOPED.
  7248. //
  7249. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  7250. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  7251. //--------------------------------------------------------------------------
  7252. typedef struct _CRYPT_SIGN_MESSAGE_PARA {
  7253.     DWORD                       cbSize;
  7254.     DWORD                       dwMsgEncodingType;
  7255.     PCCERT_CONTEXT              pSigningCert;
  7256.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7257.     void                        *pvHashAuxInfo;
  7258.     DWORD                       cMsgCert;
  7259.     PCCERT_CONTEXT              *rgpMsgCert;
  7260.     DWORD                       cMsgCrl;
  7261.     PCCRL_CONTEXT               *rgpMsgCrl;
  7262.     DWORD                       cAuthAttr;
  7263.     PCRYPT_ATTRIBUTE            rgAuthAttr;
  7264.     DWORD                       cUnauthAttr;
  7265.     PCRYPT_ATTRIBUTE            rgUnauthAttr;
  7266.     DWORD                       dwFlags;
  7267.     DWORD                       dwInnerContentType;
  7268. } CRYPT_SIGN_MESSAGE_PARA, *PCRYPT_SIGN_MESSAGE_PARA;
  7269.  
  7270. #define CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG     0x1
  7271.  
  7272. //+-------------------------------------------------------------------------
  7273. //  The CRYPT_VERIFY_MESSAGE_PARA are used to verify signed messages.
  7274. //
  7275. //  hCryptProv is used to do hashing and signature verification.
  7276. //
  7277. //  The dwCertEncodingType specifies the encoding type of the certificates
  7278. //  and/or CRLs in the message.
  7279. //
  7280. //  pfnGetSignerCertificate is called to get and verify the message signer's
  7281. //  certificate.
  7282. //
  7283. //  cbSize must be set to the sizeof(CRYPT_VERIFY_MESSAGE_PARA) or else
  7284. //  LastError will be updated with E_INVALIDARG.
  7285. //--------------------------------------------------------------------------
  7286. typedef struct _CRYPT_VERIFY_MESSAGE_PARA {
  7287.     DWORD                               cbSize;
  7288.     DWORD                               dwMsgAndCertEncodingType;
  7289.     HCRYPTPROV                          hCryptProv;
  7290.     PFN_CRYPT_GET_SIGNER_CERTIFICATE    pfnGetSignerCertificate;
  7291.     void                                *pvGetArg;
  7292. } CRYPT_VERIFY_MESSAGE_PARA, *PCRYPT_VERIFY_MESSAGE_PARA;
  7293.  
  7294. //+-------------------------------------------------------------------------
  7295. //  The CRYPT_ENCRYPT_MESSAGE_PARA are used for encrypting messages.
  7296. //
  7297. //  hCryptProv is used to do content encryption, recipient key
  7298. //  encryption, and recipient key export. Its private key
  7299. //  isn't used.
  7300. //
  7301. //  pvEncryptionAuxInfo currently isn't used and must be set to NULL.
  7302. //
  7303. //  cbSize must be set to the sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) or else
  7304. //  LastError will be updated with E_INVALIDARG.
  7305. //
  7306. //  dwFlags normally is set to 0. However, if the encoded output
  7307. //  is to be a CMSG_ENVELOPED inner content of an outer cryptographic message,
  7308. //  such as a CMSG_SIGNED, then, the CRYPT_MESSAGE_BARE_CONTENT_OUT_FLAG
  7309. //  should be set. If not set, then it would be encoded as an inner content
  7310. //  type of CMSG_DATA.
  7311. //
  7312. //  dwInnerContentType is normally set to 0. It needs to be set if the
  7313. //  ToBeEncrypted input is the encoded output of another cryptographic
  7314. //  message, such as, an CMSG_SIGNED. When set, it's one of the cryptographic
  7315. //  message types, for example, CMSG_SIGNED.
  7316. //
  7317. //  If the inner content of a nested cryptographic message is data (CMSG_DATA
  7318. //  the default), then, neither dwFlags or dwInnerContentType need to be set.
  7319. //--------------------------------------------------------------------------
  7320. typedef struct _CRYPT_ENCRYPT_MESSAGE_PARA {
  7321.     DWORD                       cbSize;
  7322.     DWORD                       dwMsgEncodingType;
  7323.     HCRYPTPROV                  hCryptProv;
  7324.     CRYPT_ALGORITHM_IDENTIFIER  ContentEncryptionAlgorithm;
  7325.     void                        *pvEncryptionAuxInfo;
  7326.     DWORD                       dwFlags;
  7327.     DWORD                       dwInnerContentType;
  7328. } CRYPT_ENCRYPT_MESSAGE_PARA, *PCRYPT_ENCRYPT_MESSAGE_PARA;
  7329.  
  7330. //+-------------------------------------------------------------------------
  7331. //  The CRYPT_DECRYPT_MESSAGE_PARA are used for decrypting messages.
  7332. //
  7333. //  The CertContext to use for decrypting a message is obtained from one
  7334. //  of the specified cert stores. An encrypted message can have one or
  7335. //  more recipients. The recipients are identified by their CertId (Issuer
  7336. //  and SerialNumber). The cert stores are searched to find the CertContext
  7337. //  corresponding to the CertId.
  7338. //
  7339. //  Only CertContexts in the store with either
  7340. //  the CERT_KEY_PROV_HANDLE_PROP_ID or CERT_KEY_PROV_INFO_PROP_ID set
  7341. //  can be used. Either property specifies the private exchange key to use.
  7342. //
  7343. //  cbSize must be set to the sizeof(CRYPT_DECRYPT_MESSAGE_PARA) or else
  7344. //  LastError will be updated with E_INVALIDARG.
  7345. //--------------------------------------------------------------------------
  7346. typedef struct _CRYPT_DECRYPT_MESSAGE_PARA {
  7347.     DWORD                   cbSize;
  7348.     DWORD                   dwMsgAndCertEncodingType;
  7349.     DWORD                   cCertStore;
  7350.     HCERTSTORE              *rghCertStore;
  7351. } CRYPT_DECRYPT_MESSAGE_PARA, *PCRYPT_DECRYPT_MESSAGE_PARA;
  7352.  
  7353. //+-------------------------------------------------------------------------
  7354. //  The CRYPT_HASH_MESSAGE_PARA are used for hashing or unhashing
  7355. //  messages.
  7356. //
  7357. //  hCryptProv is used to compute the hash.
  7358. //
  7359. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7360. //
  7361. //  cbSize must be set to the sizeof(CRYPT_HASH_MESSAGE_PARA) or else
  7362. //  LastError will be updated with E_INVALIDARG.
  7363. //--------------------------------------------------------------------------
  7364. typedef struct _CRYPT_HASH_MESSAGE_PARA {
  7365.     DWORD                       cbSize;
  7366.     DWORD                       dwMsgEncodingType;
  7367.     HCRYPTPROV                  hCryptProv;
  7368.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7369.     void                        *pvHashAuxInfo;
  7370. } CRYPT_HASH_MESSAGE_PARA, *PCRYPT_HASH_MESSAGE_PARA;
  7371.  
  7372.  
  7373.  
  7374. //+-------------------------------------------------------------------------
  7375. //  The CRYPT_KEY_SIGN_MESSAGE_PARA are used for signing messages until a
  7376. //  certificate has been created for the signature key.
  7377. //
  7378. //  pvHashAuxInfo currently isn't used and must be set to NULL.
  7379. //
  7380. //  If PubKeyAlgorithm isn't set, defaults to szOID_RSA_RSA.
  7381. //
  7382. //  cbSize must be set to the sizeof(CRYPT_KEY_SIGN_MESSAGE_PARA) or else
  7383. //  LastError will be updated with E_INVALIDARG.
  7384. //--------------------------------------------------------------------------
  7385. typedef struct _CRYPT_KEY_SIGN_MESSAGE_PARA {
  7386.     DWORD                       cbSize;
  7387.     DWORD                       dwMsgAndCertEncodingType;
  7388.     HCRYPTPROV                  hCryptProv;
  7389.     DWORD                       dwKeySpec;
  7390.     CRYPT_ALGORITHM_IDENTIFIER  HashAlgorithm;
  7391.     void                        *pvHashAuxInfo;
  7392.     CRYPT_ALGORITHM_IDENTIFIER  PubKeyAlgorithm;
  7393. } CRYPT_KEY_SIGN_MESSAGE_PARA, *PCRYPT_KEY_SIGN_MESSAGE_PARA;
  7394.  
  7395. //+-------------------------------------------------------------------------
  7396. //  The CRYPT_KEY_VERIFY_MESSAGE_PARA are used to verify signed messages without
  7397. //  a certificate for the signer.
  7398. //
  7399. //  Normally used until a certificate has been created for the key.
  7400. //
  7401. //  hCryptProv is used to do hashing and signature verification.
  7402. //
  7403. //  cbSize must be set to the sizeof(CRYPT_KEY_VERIFY_MESSAGE_PARA) or else
  7404. //  LastError will be updated with E_INVALIDARG.
  7405. //--------------------------------------------------------------------------
  7406. typedef struct _CRYPT_KEY_VERIFY_MESSAGE_PARA {
  7407.     DWORD                   cbSize;
  7408.     DWORD                   dwMsgEncodingType;
  7409.     HCRYPTPROV              hCryptProv;
  7410. } CRYPT_KEY_VERIFY_MESSAGE_PARA, *PCRYPT_KEY_VERIFY_MESSAGE_PARA;
  7411.  
  7412.  
  7413. //+-------------------------------------------------------------------------
  7414. //  Sign the message.
  7415. //
  7416. //  If fDetachedSignature is TRUE, the "to be signed" content isn't included
  7417. //  in the encoded signed blob.
  7418. //--------------------------------------------------------------------------
  7419. WINCRYPT32API
  7420. BOOL
  7421. WINAPI
  7422. CryptSignMessage(
  7423.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  7424.     IN BOOL fDetachedSignature,
  7425.     IN DWORD cToBeSigned,
  7426.     IN const BYTE *rgpbToBeSigned[],
  7427.     IN DWORD rgcbToBeSigned[],
  7428.     OUT BYTE *pbSignedBlob,
  7429.     IN OUT DWORD *pcbSignedBlob
  7430.     );
  7431.  
  7432. //+-------------------------------------------------------------------------
  7433. //  Verify a signed message.
  7434. //
  7435. //  If pbDecoded == NULL, then, *pcbDecoded is implicitly set to 0 on input.
  7436. //  For *pcbDecoded == 0 && ppSignerCert == NULL on input, the signer isn't
  7437. //  verified.
  7438. //
  7439. //  A message might have more than one signer. Set dwSignerIndex to iterate
  7440. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  7441. //
  7442. //  pVerifyPara's pfnGetSignerCertificate is called to get the signer's
  7443. //  certificate.
  7444. //
  7445. //  For a verified signer and message, *ppSignerCert is updated
  7446. //  with the CertContext of the signer. It must be freed by calling
  7447. //  CertFreeCertificateContext. Otherwise, *ppSignerCert is set to NULL.
  7448. //
  7449. //  ppSignerCert can be NULL, indicating the caller isn't interested
  7450. //  in getting the CertContext of the signer.
  7451. //
  7452. //  pcbDecoded can be NULL, indicating the caller isn't interested in getting
  7453. //  the decoded content. Furthermore, if the message doesn't contain any
  7454. //  content or signers, then, pcbDecoded must be set to NULL, to allow the
  7455. //  pVerifyPara->pfnGetCertificate to be called. Normally, this would be
  7456. //  the case when the signed message contains only certficates and CRLs.
  7457. //  If pcbDecoded is NULL and the message doesn't have the indicated signer,
  7458. //  pfnGetCertificate is called with pSignerId set to NULL.
  7459. //
  7460. //  If the message doesn't contain any signers || dwSignerIndex > message's
  7461. //  SignerCount, then, an error is returned with LastError set to
  7462. //  CRYPT_E_NO_SIGNER. Also, for CRYPT_E_NO_SIGNER, pfnGetSignerCertificate
  7463. //  is still called with pSignerId set to NULL.
  7464. //
  7465. //  Note, an alternative way to get the certificates and CRLs from a
  7466. //  signed message is to call CryptGetMessageCertificates.
  7467. //--------------------------------------------------------------------------
  7468. WINCRYPT32API
  7469. BOOL
  7470. WINAPI
  7471. CryptVerifyMessageSignature(
  7472.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7473.     IN DWORD dwSignerIndex,
  7474.     IN const BYTE *pbSignedBlob,
  7475.     IN DWORD cbSignedBlob,
  7476.     OUT BYTE OPTIONAL *pbDecoded,
  7477.     IN OUT OPTIONAL DWORD *pcbDecoded,
  7478.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7479.     );
  7480.  
  7481. //+-------------------------------------------------------------------------
  7482. //  Returns the count of signers in the signed message. For no signers, returns
  7483. //  0. For an error returns -1 with LastError updated accordingly.
  7484. //--------------------------------------------------------------------------
  7485. WINCRYPT32API
  7486. LONG
  7487. WINAPI
  7488. CryptGetMessageSignerCount(
  7489.     IN DWORD dwMsgEncodingType,
  7490.     IN const BYTE *pbSignedBlob,
  7491.     IN DWORD cbSignedBlob
  7492.     );
  7493.  
  7494. //+-------------------------------------------------------------------------
  7495. //  Returns the cert store containing the message's certs and CRLs.
  7496. //  For an error, returns NULL with LastError updated.
  7497. //--------------------------------------------------------------------------
  7498. WINCRYPT32API
  7499. HCERTSTORE
  7500. WINAPI
  7501. CryptGetMessageCertificates(
  7502.     IN DWORD dwMsgAndCertEncodingType,
  7503.     IN HCRYPTPROV hCryptProv,           // passed to CertOpenStore
  7504.     IN DWORD dwFlags,                   // passed to CertOpenStore
  7505.     IN const BYTE *pbSignedBlob,
  7506.     IN DWORD cbSignedBlob
  7507.     );
  7508.  
  7509. //+-------------------------------------------------------------------------
  7510. //  Verify a signed message containing detached signature(s).
  7511. //  The "to be signed" content is passed in separately. No
  7512. //  decoded output. Otherwise, identical to CryptVerifyMessageSignature.
  7513. //--------------------------------------------------------------------------
  7514. WINCRYPT32API
  7515. BOOL
  7516. WINAPI
  7517. CryptVerifyDetachedMessageSignature(
  7518.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7519.     IN DWORD dwSignerIndex,
  7520.     IN const BYTE *pbDetachedSignBlob,
  7521.     IN DWORD cbDetachedSignBlob,
  7522.     IN DWORD cToBeSigned,
  7523.     IN const BYTE *rgpbToBeSigned[],
  7524.     IN DWORD rgcbToBeSigned[],
  7525.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7526.     );
  7527.  
  7528. //+-------------------------------------------------------------------------
  7529. //  Encrypts the message for the recipient(s).
  7530. //--------------------------------------------------------------------------
  7531. WINCRYPT32API
  7532. BOOL
  7533. WINAPI
  7534. CryptEncryptMessage(
  7535.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  7536.     IN DWORD cRecipientCert,
  7537.     IN PCCERT_CONTEXT rgpRecipientCert[],
  7538.     IN const BYTE *pbToBeEncrypted,
  7539.     IN DWORD cbToBeEncrypted,
  7540.     OUT BYTE *pbEncryptedBlob,
  7541.     IN OUT DWORD *pcbEncryptedBlob
  7542.     );
  7543.  
  7544. //+-------------------------------------------------------------------------
  7545. //  Decrypts the message.
  7546. //
  7547. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  7548. //  For *pcbDecrypted == 0 && ppXchgCert == NULL on input, the message isn't
  7549. //  decrypted.
  7550. //
  7551. //  For a successfully decrypted message, *ppXchgCert is updated
  7552. //  with the CertContext used to decrypt. It must be freed by calling
  7553. //  CertStoreFreeCert. Otherwise, *ppXchgCert is set to NULL.
  7554. //
  7555. //  ppXchgCert can be NULL, indicating the caller isn't interested
  7556. //  in getting the CertContext used to decrypt.
  7557. //--------------------------------------------------------------------------
  7558. WINCRYPT32API
  7559. BOOL
  7560. WINAPI
  7561. CryptDecryptMessage(
  7562.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7563.     IN const BYTE *pbEncryptedBlob,
  7564.     IN DWORD cbEncryptedBlob,
  7565.     OUT OPTIONAL BYTE *pbDecrypted,
  7566.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  7567.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert
  7568.     );
  7569.  
  7570. //+-------------------------------------------------------------------------
  7571. //  Sign the message and encrypt for the recipient(s). Does a CryptSignMessage
  7572. //  followed with a CryptEncryptMessage.
  7573. //
  7574. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  7575. //  inside of an CMSG_ENVELOPED.
  7576. //--------------------------------------------------------------------------
  7577. WINCRYPT32API
  7578. BOOL
  7579. WINAPI
  7580. CryptSignAndEncryptMessage(
  7581.     IN PCRYPT_SIGN_MESSAGE_PARA pSignPara,
  7582.     IN PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
  7583.     IN DWORD cRecipientCert,
  7584.     IN PCCERT_CONTEXT rgpRecipientCert[],
  7585.     IN const BYTE *pbToBeSignedAndEncrypted,
  7586.     IN DWORD cbToBeSignedAndEncrypted,
  7587.     OUT BYTE *pbSignedAndEncryptedBlob,
  7588.     IN OUT DWORD *pcbSignedAndEncryptedBlob
  7589.     );
  7590.  
  7591. //+-------------------------------------------------------------------------
  7592. //  Decrypts the message and verifies the signer. Does a CryptDecryptMessage
  7593. //  followed with a CryptVerifyMessageSignature.
  7594. //
  7595. //  If pbDecrypted == NULL, then, *pcbDecrypted is implicitly set to 0 on input.
  7596. //  For *pcbDecrypted == 0 && ppSignerCert == NULL on input, the signer isn't
  7597. //  verified.
  7598. //
  7599. //  A message might have more than one signer. Set dwSignerIndex to iterate
  7600. //  through all the signers. dwSignerIndex == 0 selects the first signer.
  7601. //
  7602. //  The pVerifyPara's VerifySignerPolicy is called to verify the signer's
  7603. //  certificate.
  7604. //
  7605. //  For a successfully decrypted and verified message, *ppXchgCert and
  7606. //  *ppSignerCert are updated. They must be freed by calling
  7607. //  CertStoreFreeCert. Otherwise, they are set to NULL.
  7608. //
  7609. //  ppXchgCert and/or ppSignerCert can be NULL, indicating the
  7610. //  caller isn't interested in getting the CertContext.
  7611. //
  7612. //  Note: this isn't the CMSG_SIGNED_AND_ENVELOPED. Its a CMSG_SIGNED
  7613. //  inside of an CMSG_ENVELOPED.
  7614. //
  7615. //  The message always needs to be decrypted to allow access to the
  7616. //  signed message. Therefore, if ppXchgCert != NULL, its always updated.
  7617. //--------------------------------------------------------------------------
  7618. WINCRYPT32API
  7619. BOOL
  7620. WINAPI
  7621. CryptDecryptAndVerifyMessageSignature(
  7622.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7623.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7624.     IN DWORD dwSignerIndex,
  7625.     IN const BYTE *pbEncryptedBlob,
  7626.     IN DWORD cbEncryptedBlob,
  7627.     OUT OPTIONAL BYTE *pbDecrypted,
  7628.     IN OUT OPTIONAL DWORD *pcbDecrypted,
  7629.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  7630.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7631.     );
  7632.  
  7633. //+-------------------------------------------------------------------------
  7634. //  Decodes a cryptographic message which may be one of the following types:
  7635. //    CMSG_DATA
  7636. //    CMSG_SIGNED
  7637. //    CMSG_ENVELOPED
  7638. //    CMSG_SIGNED_AND_ENVELOPED
  7639. //    CMSG_HASHED
  7640. //
  7641. //  dwMsgTypeFlags specifies the set of allowable messages. For example, to
  7642. //  decode either SIGNED or ENVELOPED messages, set dwMsgTypeFlags to:
  7643. //      CMSG_SIGNED_FLAG | CMSG_ENVELOPED_FLAG.
  7644. //
  7645. //  dwProvInnerContentType is only applicable when processing nested
  7646. //  crytographic messages. When processing an outer crytographic message
  7647. //  it must be set to 0. When decoding a nested cryptographic message
  7648. //  its the dwInnerContentType returned by a previous CryptDecodeMessage
  7649. //  of the outer message. The InnerContentType can be any of the CMSG types,
  7650. //  for example, CMSG_DATA, CMSG_SIGNED, ...
  7651. //
  7652. //  The optional *pdwMsgType is updated with the type of message.
  7653. //
  7654. //  The optional *pdwInnerContentType is updated with the type of the inner
  7655. //  message. Unless there is cryptographic message nesting, CMSG_DATA
  7656. //  is returned.
  7657. //
  7658. //  For CMSG_DATA: returns decoded content.
  7659. //  For CMSG_SIGNED: same as CryptVerifyMessageSignature.
  7660. //  For CMSG_ENVELOPED: same as CryptDecryptMessage.
  7661. //  For CMSG_SIGNED_AND_ENVELOPED: same as CryptDecryptMessage plus
  7662. //      CryptVerifyMessageSignature.
  7663. //  For CMSG_HASHED: verifies the hash and returns decoded content.
  7664. //--------------------------------------------------------------------------
  7665. WINCRYPT32API
  7666. BOOL
  7667. WINAPI
  7668. CryptDecodeMessage(
  7669.     IN DWORD dwMsgTypeFlags,
  7670.     IN PCRYPT_DECRYPT_MESSAGE_PARA pDecryptPara,
  7671.     IN PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
  7672.     IN DWORD dwSignerIndex,
  7673.     IN const BYTE *pbEncodedBlob,
  7674.     IN DWORD cbEncodedBlob,
  7675.     IN DWORD dwPrevInnerContentType,
  7676.     OUT OPTIONAL DWORD *pdwMsgType,
  7677.     OUT OPTIONAL DWORD *pdwInnerContentType,
  7678.     OUT OPTIONAL BYTE *pbDecoded,
  7679.     IN OUT OPTIONAL DWORD *pcbDecoded,
  7680.     OUT OPTIONAL PCCERT_CONTEXT *ppXchgCert,
  7681.     OUT OPTIONAL PCCERT_CONTEXT *ppSignerCert
  7682.     );
  7683.  
  7684. //+-------------------------------------------------------------------------
  7685. //  Hash the message.
  7686. //
  7687. //  If fDetachedHash is TRUE, only the ComputedHash is encoded in the
  7688. //  pbHashedBlob. Otherwise, both the ToBeHashed and ComputedHash
  7689. //  are encoded.
  7690. //
  7691. //  pcbHashedBlob or pcbComputedHash can be NULL, indicating the caller
  7692. //  isn't interested in getting the output.
  7693. //--------------------------------------------------------------------------
  7694. WINCRYPT32API
  7695. BOOL
  7696. WINAPI
  7697. CryptHashMessage(
  7698.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7699.     IN BOOL fDetachedHash,
  7700.     IN DWORD cToBeHashed,
  7701.     IN const BYTE *rgpbToBeHashed[],
  7702.     IN DWORD rgcbToBeHashed[],
  7703.     OUT OPTIONAL BYTE *pbHashedBlob,
  7704.     IN OUT OPTIONAL DWORD *pcbHashedBlob,
  7705.     OUT OPTIONAL BYTE *pbComputedHash,
  7706.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7707.     );
  7708.  
  7709. //+-------------------------------------------------------------------------
  7710. //  Verify a hashed message.
  7711. //
  7712. //  pcbToBeHashed or pcbComputedHash can be NULL,
  7713. //  indicating the caller isn't interested in getting the output.
  7714. //--------------------------------------------------------------------------
  7715. WINCRYPT32API
  7716. BOOL
  7717. WINAPI
  7718. CryptVerifyMessageHash(
  7719.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7720.     IN BYTE *pbHashedBlob,
  7721.     IN DWORD cbHashedBlob,
  7722.     OUT OPTIONAL BYTE *pbToBeHashed,
  7723.     IN OUT OPTIONAL DWORD *pcbToBeHashed,
  7724.     OUT OPTIONAL BYTE *pbComputedHash,
  7725.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7726.     );
  7727.  
  7728. //+-------------------------------------------------------------------------
  7729. //  Verify a hashed message containing a detached hash.
  7730. //  The "to be hashed" content is passed in separately. No
  7731. //  decoded output. Otherwise, identical to CryptVerifyMessageHash.
  7732. //
  7733. //  pcbComputedHash can be NULL, indicating the caller isn't interested
  7734. //  in getting the output.
  7735. //--------------------------------------------------------------------------
  7736. WINCRYPT32API
  7737. BOOL
  7738. WINAPI
  7739. CryptVerifyDetachedMessageHash(
  7740.     IN PCRYPT_HASH_MESSAGE_PARA pHashPara,
  7741.     IN BYTE *pbDetachedHashBlob,
  7742.     IN DWORD cbDetachedHashBlob,
  7743.     IN DWORD cToBeHashed,
  7744.     IN const BYTE *rgpbToBeHashed[],
  7745.     IN DWORD rgcbToBeHashed[],
  7746.     OUT OPTIONAL BYTE *pbComputedHash,
  7747.     IN OUT OPTIONAL DWORD *pcbComputedHash
  7748.     );
  7749.  
  7750. //+-------------------------------------------------------------------------
  7751. //  Sign the message using the provider's private key specified in the
  7752. //  parameters. A dummy SignerId is created and stored in the message.
  7753. //
  7754. //  Normally used until a certificate has been created for the key.
  7755. //--------------------------------------------------------------------------
  7756. WINCRYPT32API
  7757. BOOL
  7758. WINAPI
  7759. CryptSignMessageWithKey(
  7760.     IN PCRYPT_KEY_SIGN_MESSAGE_PARA pSignPara,
  7761.     IN const BYTE *pbToBeSigned,
  7762.     IN DWORD cbToBeSigned,
  7763.     OUT BYTE *pbSignedBlob,
  7764.     IN OUT DWORD *pcbSignedBlob
  7765.     );
  7766.  
  7767. //+-------------------------------------------------------------------------
  7768. //  Verify a signed message using the specified public key info.
  7769. //
  7770. //  Normally called by a CA until it has created a certificate for the
  7771. //  key.
  7772. //
  7773. //  pPublicKeyInfo contains the public key to use to verify the signed
  7774. //  message. If NULL, the signature isn't verified (for instance, the decoded
  7775. //  content may contain the PublicKeyInfo).
  7776. //
  7777. //  pcbDecoded can be NULL, indicating the caller isn't interested
  7778. //  in getting the decoded content.
  7779. //--------------------------------------------------------------------------
  7780. WINCRYPT32API
  7781. BOOL
  7782. WINAPI
  7783. CryptVerifyMessageSignatureWithKey(
  7784.     IN PCRYPT_KEY_VERIFY_MESSAGE_PARA pVerifyPara,
  7785.     IN OPTIONAL PCERT_PUBLIC_KEY_INFO pPublicKeyInfo,
  7786.     IN const BYTE *pbSignedBlob,
  7787.     IN DWORD cbSignedBlob,
  7788.     OUT OPTIONAL BYTE *pbDecoded,
  7789.     IN OUT OPTIONAL DWORD *pcbDecoded
  7790.     );
  7791.  
  7792.  
  7793. //+=========================================================================
  7794. //  System Certificate Store Data Structures and APIs
  7795. //==========================================================================
  7796.  
  7797.  
  7798. //+-------------------------------------------------------------------------
  7799. //  Get a system certificate store based on a subsystem protocol.
  7800. //
  7801. //  Current examples of subsystems protocols are:
  7802. //      "MY"    Cert Store hold certs with associated Private Keys
  7803. //      "CA"    Certifying Authority certs
  7804. //      "ROOT"  Root Certs
  7805. //      "SPC"   Software publisher certs
  7806. //
  7807. //
  7808. //  If hProv is NULL the default provider "1" is opened for you.
  7809. //  When the store is closed the provider is release. Otherwise
  7810. //  if hProv is not NULL, no provider is created or released.
  7811. //
  7812. //  The returned Cert Store can be searched for an appropriate Cert
  7813. //  using the Cert Store API's (see certstor.h)
  7814. //
  7815. //  When done, the cert store should be closed using CertStoreClose
  7816. //--------------------------------------------------------------------------
  7817.  
  7818.  
  7819. WINCRYPT32API HCERTSTORE WINAPI CertOpenSystemStoreA(
  7820.     HCRYPTPROV      hProv,
  7821.     LPCSTR            szSubsystemProtocol
  7822.     );
  7823. WINCRYPT32API HCERTSTORE WINAPI CertOpenSystemStoreW(
  7824.     HCRYPTPROV      hProv,
  7825.     LPCWSTR            szSubsystemProtocol
  7826.     );
  7827. #ifdef UNICODE
  7828. #define CertOpenSystemStore  CertOpenSystemStoreW
  7829. #else
  7830. #define CertOpenSystemStore  CertOpenSystemStoreA
  7831. #endif // !UNICODE
  7832.  
  7833. WINCRYPT32API BOOL WINAPI CertAddEncodedCertificateToSystemStoreA(
  7834.     LPCSTR            szCertStoreName,
  7835.     const BYTE *    pbCertEncoded,
  7836.     DWORD           cbCertEncoded
  7837.     );
  7838. WINCRYPT32API BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(
  7839.     LPCWSTR            szCertStoreName,
  7840.     const BYTE *    pbCertEncoded,
  7841.     DWORD           cbCertEncoded
  7842.     );
  7843. #ifdef UNICODE
  7844. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreW
  7845. #else
  7846. #define CertAddEncodedCertificateToSystemStore  CertAddEncodedCertificateToSystemStoreA
  7847. #endif // !UNICODE
  7848.  
  7849.  
  7850. //+-------------------------------------------------------------------------
  7851. //  Find all certificate chains tying the given issuer name to any certificate
  7852. //  that the current user has a private key for.
  7853. //
  7854. //  If no certificate chain is found, FALSE is returned with LastError set
  7855. //  to CRYPT_E_NOT_FOUND and the counts zeroed.
  7856. //
  7857. //  IE 3.0 ASSUMPTION:
  7858. //   The client certificates are in the "My" system store. The issuer
  7859. //   cerificates may be in the "Root", "CA" or "My" system stores.
  7860. //--------------------------------------------------------------------------
  7861. typedef struct _CERT_CHAIN {
  7862.     DWORD                   cCerts;     // number of certs in chain
  7863.     PCERT_BLOB              certs;      // pointer to array of cert chain blobs
  7864.                                         // representing the certs
  7865.     CRYPT_KEY_PROV_INFO     keyLocatorInfo; // key locator for cert
  7866. } CERT_CHAIN, *PCERT_CHAIN;
  7867.  
  7868.  
  7869. // WINCRYPT32API    This is not exported by crypt32, it is exported by softpub
  7870. HRESULT
  7871. WINAPI
  7872. FindCertsByIssuer(
  7873.     OUT PCERT_CHAIN pCertChains,
  7874.     IN OUT DWORD *pcbCertChains,
  7875.     OUT DWORD *pcCertChains,        // count of certificates chains returned
  7876.     IN BYTE* pbEncodedIssuerName,   // DER encoded issuer name
  7877.     IN DWORD cbEncodedIssuerName,   // count in bytes of encoded issuer name
  7878.     IN LPCWSTR pwszPurpose,         // "ClientAuth" or "CodeSigning"
  7879.     IN DWORD dwKeySpec              // only return signers supporting this
  7880.                                     // keyspec
  7881.     );
  7882.  
  7883. #ifdef __cplusplus
  7884. }       // Balance extern "C" above
  7885. #endif
  7886.  
  7887.  
  7888. #endif // __WINCRYPT_H__
  7889.